199. Binary Tree Right Side View
https://leetcode.com/problems/binary-tree-right-side-view/
Python
class Solution:
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
return self._travel(root, 0, [])
def _travel(self, node, level, result):
if not node:
return result
if len(result) < level+1:
result.append(None)
result[level] = node.val
self._travel(node.left, level+1, result)
self._travel(node.right, level+1, result)
return result