56ms, python ,up to down,simple and easy


  • 0
    M
    def binaryTreePaths(self, root): #56ms 
        result = []
        def getPaths(root, result, path=''):
            if not root:
                return result
            if not(root.left or root.right):
                result.append(path + `root.val`)
                return result
            getPaths(root.left, result, path + `root.val` + '->')
            getPaths(root.right, result, path + `root.val` +'->')
            return result
        return getPaths(root, result)

Log in to reply
 

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