MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / rightSideView

Method rightSideView

python/0199-binary-tree-right-side-view.py:8–24  ·  view source on GitHub ↗
(self, root: TreeNode)

Source from the content-addressed store, hash-verified

6# self.right = right
7class Solution:
8 def rightSideView(self, root: TreeNode) -> List[int]:
9 res = []
10 q = collections.deque([root])
11
12 while q:
13 rightSide = None
14 qLen = len(q)
15
16 for i in range(qLen):
17 node = q.popleft()
18 if node:
19 rightSide = node
20 q.append(node.left)
21 q.append(node.right)
22 if rightSide:
23 res.append(rightSide.val)
24 return res

Callers

nothing calls this directly

Calls 1

popleftMethod · 0.80

Tested by

no test coverage detected