Last active
November 30, 2016 16:10
-
-
Save pyrofolium/9529bc01574c44b5d4b5fbbf304de2f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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