Simple python solution with less than 10 lines


  • -1
    P
    class Solution:
        def getChild(self,root):
            if not root:
                return []
            tmp = self.getChild(root.left)+self.getChild(root.right)
            return [str(root.val)+'->'+str(i) for i in tmp] if tmp else [str(root.val)]
    
        # @param {TreeNode} root
        # @return {string[]}
        def binaryTreePaths(self, root):
            if not root:
                return []
            return self.getChild(root)

Log in to reply
 

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