BFS 44ms Python Solution

  • 2
    class Solution(object):
        def rightSideView(self, root):
            :type root: TreeNode
            :rtype: List[int]
            if not root:return []
            prevLvl = [root]
            ret = []
            while prevLvl:
                T = list(prevLvl)
                prevLvl[:] = []
                for node in T:
                    if node.right: prevLvl.append(node.right)
                    if node.left: prevLvl.append(node.left)
            return ret

Log in to reply

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