File tree Expand file tree Collapse file tree 1 file changed +0
-35
lines changed
leetcode-algorithms/src/main/java/com/stevesun/solutions Expand file tree Collapse file tree 1 file changed +0
-35
lines changed Original file line number Diff line number Diff line change @@ -22,39 +22,4 @@ public boolean hasPathSum(TreeNode root, int sum) {
22
22
return hasPathSum (root .left , sum - root .val ) || hasPathSum (root .right , sum - root .val );
23
23
}
24
24
25
- public static void main (String ...strings ){
26
- PathSum test = new PathSum ();
27
- TreeNode root = new TreeNode (5 );
28
- root .left = new TreeNode (4 );
29
- int sum = 5 ;
30
-
31
- // TreeNode root = new TreeNode(1);
32
- // root.left = new TreeNode(-2);
33
- // root.left.left = new TreeNode(1);
34
- // root.left.right = new TreeNode(3);
35
- // root.right = new TreeNode(-3);
36
- // root.right.left = new TreeNode(-2);
37
- // root.left.left.left = new TreeNode(-1);
38
- // int sum = 2;
39
- // 1
40
- // / \
41
- // -2 -3
42
- // / \ /
43
- // 1 3 -2
44
- // /
45
- // -1
46
- // System.out.println(test.hasPathSum(root, sum));
47
- System .out .println (test .hasPathSumAgain (root , sum ));
48
- }
49
-
50
-
51
- public boolean hasPathSumAgain (TreeNode root , int sum ) {
52
- if (root == null ) return false ;
53
- if (root .left == null && root .right == null ){
54
- if (sum == root .val ) return true ;
55
- else return false ;
56
- }
57
- return hasPathSum (root .left , sum - root .val ) || hasPathSum (root .right , sum - root .val );
58
- }
59
-
60
25
}
You can’t perform that action at this time.
0 commit comments