Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created August 10, 2017 03:02
Show Gist options
  • Select an option

  • Save cixuuz/64758636be98a3caa1adc2d6a518ebd9 to your computer and use it in GitHub Desktop.

Select an option

Save cixuuz/64758636be98a3caa1adc2d6a518ebd9 to your computer and use it in GitHub Desktop.
[112. Path Sum] #lc112
public class Solution {
public boolean hasPathSum(TreeNode root, int sum) {
if (root == null) return false;
if (root.left == null && root.right == null) return sum == root.val;
sum -= root.val;
boolean l = hasPathSum(root.left, sum);
boolean r = hasPathSum(root.right, sum);
sum += root.val;
return l || r;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment