[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/mJackie/leetcode/master/code/lc112.java [Back]  [Original]

package code;
/*
 * 112. Path Sum
 * sum
 * Easy
 * 
 * 
 * Tipslc112, lc113, lc437, lc129, lc124, lc337
 *  lc112 sum
 *         lc113 lc112
 *         lc437 
 *         lc129 
 *         lc124 
 *         lc337 dp
 */
public class lc112 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) {
            val = x;
        }
    }
    public boolean hasPathSum(TreeNode root, int sum) {
        if(root==null) return false;
        if(root.val==sum&&root.left==null&&root.right==null) return true;
        return hasPathSum(root.left, sum-root.val)||hasPathSum(root.right, sum-root.val);
    }
}

Web Proxy Viewer  |  New URL  |  Original Page