48ms concise python solution


  • 0
    Y
    class Solution:
        # @param {TreeNode} root
        # @return {integer[]}
        def rightSideView(self, root):
            res = []
            self.right_side_view_help(root, 0, [0], res)
            return res
    
        def right_side_view_help(self, root, curr, level, res):
            if not root:
                return
    
            if curr >= level[0]:
                res.append(root.val)
                level[0] += 1
    
            curr += 1
            self.right_side_view_help(root.right, curr, level, res)
            self.right_side_view_help(root.left, curr, level, res)

  • 0
    C

    why do you use [0] instead of 0 for level?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.