leetcode1028】的更多相关文章

We run a preorder depth first search on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.  (If the depth of a node is D, the depth of its immediat…
class Solution(object): def __init__(self): self.List = list() def rdfs(self,S): if S != '': length = len(S) depth = len(self.List) tempval = '' tempdepth = 0 for i in range(length): s = S[i] if s != '-': tempval += s if i == length - 1: while depth…
1028. 从先序遍历还原二叉树 python 100%内存 一次遍历     题目 我们从二叉树的根节点 root 开始进行深度优先搜索. 在遍历中的每个节点处,我们输出 D 条短划线(其中 D 是该节点的深度),然后输出该节点的值.(如果节点的深度为 D,则其直接子节点的深度为 D + 1.根节点的深度为 0). 如果节点只有一个子节点,那么保证该子节点为左子节点. 给出遍历输出 S,还原树并返回其根节点 root. 示例 1: 输入:"1-2--3--4-5--6--7"输出:[…