'''
Description:
Autor: Au3C2
Date: 2021-03-18 16:22:15
LastEditors: Au3C2
LastEditTime: 2021-03-18 16:22:28
'''
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def binaryTreePaths(self, root: TreeNode) -> List[str]:
self.path_list = list()
t = list()
self.recursion(root,t)
res = list()
for path in self.path_list:
res.append('->'.join(path))
return res
def recursion(self,root,t):
if not root:
return 0
else:
t.append(str(root.val))
if not root.left and not root.right:
self.path_list.append(list(t))
self.recursion(root.left,t)
self.recursion(root.right,t)
t.pop()
# 树,简单
# https://leetcode-cn.com/problems/binary-tree-paths/