Submission Detail

189 / 189 test cases passed.
Status:

Accepted

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

Accepted Solutions Runtime Distribution

0
2
4
6
8
10
12
14
16
18
10
20
30
40
java
Runtime (ms)
Distribution (%)

0
2
4
6
8
10
12
14
16
18
10
20
30
40
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

41500
41750
42000
42250
42500
42750
43000
43250
43500
5
10
15
java
You are here!
Your memory usage beats 95.15 % of java submissions.
Memory (KB)
Distribution (%)

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

Invite friends to challenge Minimum Absolute Difference in BST


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
/**
* 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 int getMinimumDifference(TreeNode root) {
ArrayList<Integer> allNodes = new ArrayList<>();
allNodes = inOrder(root,allNodes);
int diff = 999999;
for (int i = 0; i < allNodes.size()-1; i++) {
for (int j = i+1; j < allNodes.size(); j++) {
int abs_diff = Math.abs(allNodes.get(i) - allNodes.get(j));
if (abs_diff < diff)
diff = abs_diff;
}
}
return diff;
}
public ArrayList<Integer> inOrder(TreeNode root, ArrayList<Integer> iot) {
if (root == null)
return iot;
iot = inOrder(root.left,iot);
iot.add(root.val);
iot = inOrder(root.right,iot);
return iot;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX