We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 451dd70 commit aec31a7Copy full SHA for aec31a7
src/leetcode2018/Trees.java
@@ -5,6 +5,8 @@
5
import java.util.List;
6
import java.util.Queue;
7
8
+import amazon.TreeNode;
9
+
10
11
public class Trees {
12
@@ -134,6 +136,16 @@ public List<List<Integer>> levelOrder(TreeNode root) {
134
136
return re;
135
137
}
138
139
+ public boolean hasPathSum(TreeNode root, int sum) {
140
+ if(root==null) return false;
141
+ System.out.println(root.val);
142
+ if(root.left==null && root.right==null) {
143
+ System.out.println(root.val +" ="+ sum);
144
+ return sum == root.val;
145
+ }
146
+ return hasPathSum(root.left, sum-root.val) || hasPathSum(root.right,sum-root.val);
147
148
149
150
151
class TreeNode{
0 commit comments