We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 40b7f0c commit efb79edCopy full SHA for efb79ed
MEDIUM/src/medium/BinaryTreeRightSideView.java
@@ -35,14 +35,12 @@ public List<Integer> rightSideView(TreeNode root) {
35
while(!q.isEmpty()){
36
int currentSize = q.size();
37
int i = 0;
38
- for(; i < currentSize-1; i++){
39
- TreeNode currentNode = q.poll();
+ TreeNode currentNode = null;
+ for(; i < currentSize; i++){
40
+ currentNode = q.poll();
41
if(currentNode.left != null) q.offer(currentNode.left);
42
if(currentNode.right != null) q.offer(currentNode.right);
43
}
44
- if(currentNode.left != null) q.offer(currentNode.left);
45
- if(currentNode.right != null) q.offer(currentNode.right);
46
res.add(currentNode.val);
47
48
return res;
0 commit comments