Easy 5 line python code

  • 1
    def rootToLeafPaths(self, root):
       if not root: 
         return []
       if not root.left and not root.right: 
         return [str(root.val)]
       return [str(root.val) + '->' + i for i in self.rootToLeafPaths(root.left)] + [str(root.val) + '->' + i for i in self.rootToLeafPaths(root.right)]

Log in to reply

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