码迷,mamicode.com
首页 >  
搜索关键字:inorder traversal    ( 1831个结果
leetcode7:binary-tree-preorder-traversal
题目描述 求给定的二叉树的前序遍历。 例如: 给定的二叉树为{1,#,2,3}, 1 \ 2 / 3 返回:[1,2,3]. 备注;用递归来解这道题太没有新意了,可以给出迭代的解法么? /** * struct TreeNode { * int val; * struct TreeNode *lef ...
分类:其他好文   时间:2020-08-05 13:09:09    阅读次数:71
1020 Tree Traversals (25分)
题干 Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to ...
分类:其他好文   时间:2020-07-29 21:34:20    阅读次数:77
LC1008 Construct Binary Search Tree from Preorder Traversal
根据BST的前序遍历重建BST 1. 平均O(NlogN) 最坏O(N^2) class Solution { public: TreeNode* dfs(int l, int r, vector<int>& p) { if (l > r) return nullptr; TreeNode* nod ...
分类:其他好文   时间:2020-07-23 16:13:09    阅读次数:67
03-树3 Tree Traversals Again (25分)
03-树3 Tree Traversals Again (25分) An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that w ...
分类:其他好文   时间:2020-07-19 23:08:36    阅读次数:84
leetcode-----94. 二叉树的中序遍历
链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNo ...
分类:其他好文   时间:2020-07-18 11:34:31    阅读次数:66
LeetCode 590 N叉树的后序遍历
题目链接:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/ 方法一递归法:先访问子节点,然后访问根。LeetCode代码: /* // Definition for a Node. class Node { public ...
分类:其他好文   时间:2020-07-16 21:39:10    阅读次数:79
LeetCode94二叉树中序遍历
题目链接 https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 题解一:递归 // Problem: LeetCode 94 // URL: https://leetcode-cn.com/problems/binary-tr ...
分类:其他好文   时间:2020-07-13 15:36:49    阅读次数:58
LeetCode144二叉树前序遍历
题目链接 https://leetcode-cn.com/problems/binary-tree-preorder-traversal/description/ 题解一:递归 // Problem: LeetCode 144 // URL: https://leetcode-cn.com/prob ...
分类:其他好文   时间:2020-07-13 00:00:50    阅读次数:90
LeetCode 102 二叉树的层序遍历
题目描述链接:https://leetcode-cn.com/problems/binary-tree-level-order-traversal/ 解题思路:参考官方题解,解题思路如下:对于二叉树的层序遍历,首先应该考虑到的数据结构便是队列,利用队列现进先出的特性,可以很方便的解决此题。 (1)根 ...
分类:其他好文   时间:2020-07-12 20:29:04    阅读次数:65
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-07-10 11:20:42    阅读次数:63
1831条   上一页 1 2 3 4 5 6 ... 184 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!