Skip to content

Instantly share code, notes, and snippets.

@pyrofolium
Last active November 30, 2016 16:10
Show Gist options
  • Save pyrofolium/9529bc01574c44b5d4b5fbbf304de2f3 to your computer and use it in GitHub Desktop.
Save pyrofolium/9529bc01574c44b5d4b5fbbf304de2f3 to your computer and use it in GitHub Desktop.
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def __init__(self):
self.result = []
self.current_level = 0
self.max_level = self.current_level
def rightSideView(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
if root == None:
return self.result
if self.current_level >= self.max_level:
self.result.append(root.val)
self.current_level += 1
self.max_level = max(self.current_level, self.max_level)
self.rightSideView(root.right)
self.rightSideView(root.left)
self.current_level -= 1
return self.result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment