Share simple python solution, BFS+level record


  • 0
    Y
    class Solution(object):
        def findBottomLeftValue(self, root):
            if not root: return None
            queue=collections.deque([(root,1)])
            dic=collections.defaultdict(list)
            while queue:
                root,level=queue.popleft()
                if not root:
                    continue
                dic[level].append(root.val)
                if root.left:
                    queue.append((root.left,level+1))
                if root.right:
                    queue.append((root.right,level+1))
            maxL=max(dic)
            return dic[maxL][0]
    

Log in to reply
 

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