码迷,mamicode.com
首页 >  
搜索关键字:preorder traversal    ( 1851个结果
429. N-ary Tree Level Order Traversal
Given an n-ary tree, return the level order traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversa ...
分类:其他好文   时间:2020-02-18 09:23:25    阅读次数:66
leetcode94 Binary Tree Inorder Traversal
1 """ 2 Given a binary tree, return the inorder traversal of its nodes' values. 3 Example: 4 Input: [1,null,2,3] 5 1 6 \ 7 2 8 / 9 3 10 Output: [1,3,2 ...
分类:其他好文   时间:2020-02-13 22:54:06    阅读次数:53
[LeetCode] 107. Binary Tree Level Order Traversal II
二叉树层序遍历二。题意跟版本一很接近,唯一的不同点是输出的output需要从下往上排列,叶子节点层最先输出,根节点在最后输出。例子, For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return i ...
分类:其他好文   时间:2020-02-11 09:30:26    阅读次数:53
迭代遍历二叉树
二叉树的递归遍历很容易写出来,对于递归遍历则需要借助辅助栈,并且不同的遍历次序迭代的写法也不尽相同,这里整理一些二叉树迭代遍历的实现 二叉树的前序遍历 [leetcode144]:https://leetcode cn.com/problems/binary tree preorder traver ...
分类:其他好文   时间:2020-02-11 00:35:37    阅读次数:73
深度优先遍历和广度优先遍历
深度优先遍历(Depth First Search): 自顶点起, 往下一个邻近点走,一直走,走不动了,退回一部。这样反复; /*深度优先遍历三种方式*/ let deepTraversal1 = (node, nodeList = []) => { if (node !== null) { nod ...
分类:其他好文   时间:2020-02-07 22:23:41    阅读次数:68
[LeetCode] 103. Binary Tree Zigzag Level Order Traversal
二叉树之字形层序遍历。题意是给一个二叉树,对其进行层序遍历,但是在遍历每一层的时候要一次从左开始一次从右开始。例子, Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level orde ...
分类:其他好文   时间:2020-02-06 10:24:34    阅读次数:81
刷题--二叉树(2)
二叉树结构变化 例 lintcode 453. Flatten Binary Tree to Linked List https://www.lintcode.com/problem/flatten-binary-tree-to-linked-list/ traversal :因为是按照前序遍历的顺 ...
分类:其他好文   时间:2020-02-05 10:04:59    阅读次数:68
leetcode105 Construct Binary Tree from Preorder and Inorder Traversal
1 """ 2 For example, given 3 preorder = [3,9,20,15,7] 4 inorder = [9,3,15,20,7] 5 Return the following binary tree: 6 3 7 / \ 8 9 20 9 / \ 10 15 7 11 ...
分类:其他好文   时间:2020-02-02 23:34:00    阅读次数:66
二叉树的遍历
二叉树的遍历 前序遍历 "Leetcode preorder" 中序遍历 "Leetcode inorder" 后续遍历 "Leetcode postorder" Morris Traversal 前序遍历 递归 时间O(n), 空间O(n) 非递归 时间O(n), 空间O(n) 中序遍历 递归 非 ...
分类:其他好文   时间:2020-02-02 15:55:30    阅读次数:63
leetcode1343
1 class Solution: 2 def __init__(self): 3 self.subTrees = [] 4 self.sums = 0 5 self.memo = {} 6 def preOrder(self,root): 7 if root != None: 8 self.sum ...
分类:其他好文   时间:2020-02-02 13:31:56    阅读次数:62
1851条   上一页 1 ... 10 11 12 13 14 ... 186 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!