Submission Detail

61 / 61 test cases passed.
Status:

Accepted

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

Accepted Solutions Runtime Distribution

17.5
20.0
7.5
10.0
12.5
15.0
22.5
25.0
27.5
30.0
10
20
30
40
50
java
You are here!
Your runtime beats 99.12 % of java submissions.
Runtime (ms)
Distribution (%)

17.5
20.0
7.5
10.0
12.5
15.0
22.5
25.0
27.5
30.0
20
40
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

46400
45800
45900
46000
46100
46200
46300
46500
46600
46700
46800
46900
47000
5
10
15
20
java
You are here!
Your memory usage beats 59.22 % of java submissions.
Memory (KB)
Distribution (%)

46400
45800
45900
46000
46100
46200
46300
46500
46600
46700
46800
46900
47000
5
10
15
20
Zoom area by dragging across this chart

Invite friends to challenge Binary Search Tree Iterator


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
56
/**
* 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 BSTIterator {
ArrayList<TreeNode> BST;
int current;
public BSTIterator(TreeNode root) {
ArrayList<TreeNode> iot = new ArrayList<>();
this.BST = inOrder(root,iot);
TreeNode init = new TreeNode(-1);
this.BST.add(0,init);
this.current = 0;
}
public int next() {
return this.BST.get(++current).val;
}
public boolean hasNext() {
if (current < this.BST.size()-1)
return true;
return false;
}
public ArrayList<TreeNode> inOrder(TreeNode root, ArrayList<TreeNode> iot) {
if (root == null)
return iot;
iot = inOrder(root.left,iot);
iot.add(root);
iot = inOrder(root.right,iot);
return iot;
}
}
/**
* Your BSTIterator object will be instantiated and called as such:
* BSTIterator obj = new BSTIterator(root);
* int param_1 = obj.next();
* boolean param_2 = obj.hasNext();
*/
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX