Created
August 10, 2017 03:02
-
-
Save cixuuz/64758636be98a3caa1adc2d6a518ebd9 to your computer and use it in GitHub Desktop.
[112. Path Sum] #lc112
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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