Python iterative easy to read

  • 0
    class Solution(object):
        def rightSideView(self, root):
            if not root: 
                return []
                res, stk = [], []
                stk.append((root, 0))
                while stk:
                    node, cur = stk.pop()
                    if len(res) == cur:
                    if node.left:
                        stk.append((node.left, cur + 1))
                    if node.right:
                        stk.append((node.right, cur + 1))
                return res

Log in to reply

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