Skip to content

Commit a46ebde

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Create 199. Binary Tree Right Side View.py
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com> Co-Authored-By: Shiwangi Srivastava <174641070+IamShiwangi@users.noreply.github.com>
1 parent 5d1df5d commit a46ebde

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
9+
ans = []
10+
if root is None:
11+
return ans
12+
q = deque([root])
13+
while q:
14+
ans.append(q[0].val)
15+
for _ in range(len(q)):
16+
node = q.popleft()
17+
if node.right:
18+
q.append(node.right)
19+
if node.left:
20+
q.append(node.left)
21+
return ans

0 commit comments

Comments
 (0)