6 lines python recursive solution


  • 0
    G
        def binaryTreePaths(self, root):
            if not root:
                return []
            elif not root.left and not root.right:
                return [str(root.val)]
            else:
                return list(map(lambda x: str(root.val)+"->"+x, self.binaryTreePaths(root.left)+self.binaryTreePaths(root.right)))
    

Log in to reply
 

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