Submission Detail

117 / 117 test cases passed.
Status:

Accepted

Runtime: 0 ms
Memory Usage: 43.3 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
1
2
3
4
5
6
7
8
9
10
11
20
40
60
80
100
java
You are here!
Your runtime beats 100.00 % of java submissions.
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
11
50
100
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

41600
41800
42000
42200
42400
42600
42800
43000
43200
43400
43600
43800
2
4
6
8
10
java
You are here!
Your memory usage beats 49.99 % of java submissions.
Memory (KB)
Distribution (%)

41750
42000
42250
42500
42750
43000
43250
43500
43750
5
10
Zoom area by dragging across this chart

Invite friends to challenge Path Sum


Submitted Code: 0 minutes ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public boolean hasPathSum(TreeNode root, int targetSum) {
if (root == null)
return false;
boolean found = false;
int currentSum = 0;
boolean pathSum = inOrder(root,currentSum,targetSum,found);
if (pathSum == true)
return true;
else
return false;
}
public boolean inOrder(TreeNode root,int current, int target, boolean found) {
if (found == true)
return true;
if (root == null)
return found;
current += root.val;
if (root.left == null && root.right == null && current == target)
return true;
if (root.left == null && root.right == null && current != target)
return false;
found = inOrder(root.left,current,target,found);
found = inOrder(root.right,current,target,found);
return found;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX