MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Tree/BinaryTreeRightSideView.py:33–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31# self.right = None
32
33class Solution(object):
34 def rightSideView(self, root):
35 """
36 :type root: TreeNode
37 :rtype: List[int]
38 """
39 if not root:
40 return []
41
42 result = [root.val]
43
44 current = [root]
45 next_nodes = []
46
47 while current or next_nodes:
48 for i in current:
49 if i.left:
50 next_nodes.append(i.left)
51 if i.right:
52 next_nodes.append(i.right)
53 if next_nodes:
54
55 result.append(next_nodes[-1].val)
56 current = next_nodes
57 next_nodes = []
58
59 return result
60

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected