# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution(object):
    def binaryTreePaths(self, root):
        result = []
        def paths(root,path):
            if root.left is None and root.right is None:
                result.append(path+str(root.val))
            if root.left is not None:
                paths(root.left,path+str(root.val)+"->")
            if root.right is not None:
                paths(root.right,path+str(root.val)+"->")

        if root is not None:
            paths(root,"")
        return result