3 line Python DFS


  • 0
    class Solution(object):
        def binaryTreePaths(self, root):
            if not root:
                return []
            return [str(root.val) + ("->" if path else '') + path for path in self.binaryTreePaths(root.left) + self.binaryTreePaths(root.right) or ['']]
            
    

Log in to reply
 

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