Submission Detail

216 / 216 test cases passed.
Status:

Accepted

Runtime: 1 ms
Memory Usage: 40.9 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
30
40
50
60
70
java
Runtime (ms)
Distribution (%)

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

Accepted Solutions Memory Distribution

40400
40500
40600
40700
40800
40900
41000
41100
41200
41300
41400
41500
41600
41700
5
10
15
20
java
You are here!
Your memory usage beats 98.54 % of java submissions.
Memory (KB)
Distribution (%)

40400
40500
40600
40700
40800
40900
41000
41100
41200
41300
41400
41500
41600
41700
5
10
15
20
Zoom area by dragging across this chart

Invite friends to challenge Binary Tree Right Side View


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
/**
* 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 List<Integer> rightSideView(TreeNode root) {
LinkedList<TreeNode> queue = new LinkedList<>();
LinkedList<TreeNode> next_queue = new LinkedList<>();
ArrayList<Integer> rightView = new ArrayList<>();
if (root == null)
return rightView;
queue.add(root);
while (queue.size() > 0) {
for (int i = 0; i < queue.size(); i++) {
TreeNode n = queue.get(i);
if (n.left != null)
next_queue.add(n.left);
if (n.right != null)
next_queue.add(n.right);
if (i == queue.size()-1)
rightView.add(n.val);
}
queue = next_queue;
next_queue = new LinkedList<>();
}
return rightView;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX