My 64ms solution in python

  • 0
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    class Solution:
        # @param {TreeNode} root
        # @return {string[]}
        def binaryTreePaths(self, root):
            if root==None:
                return []
            if root.left==None and root.right==None:
                return [str(root.val)]
            return [str(root.val)+'->'+i for i in res]

Log in to reply

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