Skip to content

Commit b6460dd

Browse files
author
Partho Biswas
committed
no message
1 parent b8725dd commit b6460dd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

leetcode.com/python/199_Binary_Tree_Right_Side_View.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,27 @@ def rightSideView(self, root):
2828
rightView.append(node.val)
2929
return rightView
3030

31+
32+
33+
# My solution during mock contest
34+
from collections import deque
35+
class Solution(object):
36+
def rightSideView(self, root):
37+
"""
38+
:type root: TreeNode
39+
:rtype: List[int]
40+
"""
41+
queue = deque([root])
42+
rightView = []
43+
while queue:
44+
currentLevelLen = len(queue)
45+
for i in range(currentLevelLen):
46+
currentNode = queue.popleft()
47+
if currentNode:
48+
if i == currentLevelLen - 1:
49+
rightView.append(currentNode.val)
50+
if currentNode.left:
51+
queue.append(currentNode.left)
52+
if currentNode.right:
53+
queue.append(currentNode.right)
54+
return rightView

0 commit comments

Comments
 (0)