public boolean hasPathSum(TreeNode root, int sum) {
        if(root == null)
            return false;
        int remain = sum - root.val;
        if(root.left==null && root.right==null)
            if(0 == remain)
                return true;
            else
                return false;
        return hasPathSum(root.left, remain) || hasPathSum(root.right, remain);
    }