257. Binary Tree Paths打印二叉树路径
来源:互联网 发布:sql 查询多条结果合并 编辑:程序博客网 时间:2024/06/08 17:21
# 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):
"""
:type root: TreeNode
:rtype: List[str]
"""
res = []
if root:
self.getPath(root,'',res)
return res
def getPath(self,node,line,res):
if not node.left and not node.right:
res.append(line+str(node.val))
if node.left:
s=line+str(node.val)+'->'
self.getPath(node.left,s,res)
if node.right:
s=line+str(node.val)+'->'
self.getPath(node.right,s,res)
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def binaryTreePaths(self, root):
"""
:type root: TreeNode
:rtype: List[str]
"""
res = []
if root:
self.getPath(root,'',res)
return res
def getPath(self,node,line,res):
if not node.left and not node.right:
res.append(line+str(node.val))
if node.left:
s=line+str(node.val)+'->'
self.getPath(node.left,s,res)
if node.right:
s=line+str(node.val)+'->'
self.getPath(node.right,s,res)
阅读全文
0 0
- 257. Binary Tree Paths(打印二叉树所有路径)
- 257. Binary Tree Paths打印二叉树路径
- Binary Tree Paths (二叉树路径遍历)
- 257. Binary Tree Paths 二叉树的路径
- 257. Binary Tree Paths | 二叉树的路径
- 【二叉树】字符串打印树结构/路径【606. Construct String from Binary Tree】【257. Binary Tree Paths】【102. Binary Tree Le
- 【二叉树】257. Binary Tree Paths
- Tree----- 257. Binary Tree Paths(二叉树从根节点开始的所有路径)
- LeetCode OJ 之 Binary Tree Paths(二叉树路径)
- lintcode binary-tree-paths 二叉树的所有路径
- Binary Tree Paths(二叉树的路径)
- 【Leetcode】257 Binary Tree Paths 二叉树的路径
- 257.leetcode Binary Tree Paths(easy)[二叉树深度路径遍历]
- 257. Binary Tree Paths (求二叉树中所有根到叶子的路径)
- Binary Tree Paths 二叉树遍历
- leetcode 257. Binary Tree Paths-树路径|深度搜索
- Binary Tree Paths 二叉树的路径(含创建树的代码)
- Binary Tree Paths 二叉树所有从跟节点到叶子节点的路径
- LightOJ
- 积分与导数原理
- CF #611 H, New Year And Forgotten Tree
- KeyPoint&DMatch类型简介
- 真 · windows环境下php7.0以上开启curl方法
- 257. Binary Tree Paths打印二叉树路径
- 数量金融学(6):TIPP策略
- TCP 的超时与重传
- TreeSet保证元素唯一性
- dedecms模板教程:dedecms模板如何使用?
- android中常用adb命令
- Java 中文件的加密与解密
- Java+Selenium3方法篇37-Robot类处理文件上传
- Redis集群教程