Skip to content

Commit

Permalink
Update binary-tree-right-side-view.py
Browse files Browse the repository at this point in the history
Last node in list is always the right most view.
  • Loading branch information
NYCGithub authored Sep 15, 2018
1 parent 5810b7e commit 48b995a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Python/binary-tree-right-side-view.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ def rightSideView(self, root):
result, current = [], [root]
while current:
next_level = []
for i, node in enumerate(current):
for node in current:
if node.left:
next_level.append(node.left)
if node.right:
next_level.append(node.right)
if i == len(current) - 1:
result.append(node.val)
next_level.append(node.right)
result.append(node.val)
current = next_level

return result

0 comments on commit 48b995a

Please sign in to comment.