[LeetCode]257. Binary Tree Paths

257. Binary Tree Paths

class Solution(object):
    def binaryTreePaths(self, root):
        """
        :type root: TreeNode
        :rtype: List[str]
        """
        def helper(node, path):
            if not node.left and not node.right:
                res.append(path)
                return
            print path
            if node.left:
                helper(node.left, path + '->' + str(node.left.val))
            if node.right:
                helper(node.right, path + '->' + str(node.right.val))
        if not root:
            return []
        res = []
        helper(root, str(root.val))
        return res
posted @ 2017-08-30 13:49  banananana  阅读(104)  评论(0编辑  收藏  举报