Given a binary tree, return the preorder traversal of its nodes’ values.For example:
Given binary tree{1,#,2,3}, 1
2
/
3return [1,2,3].递归遍历:/**C++
* Definition for a binary tree n...
分类:
其他好文 时间:
2015-06-13 11:27:51
阅读次数:
143
树的遍历当初觉得难死,现在还好public class Solution { public ArrayList preorderTraversal(TreeNode root) { ArrayList res = new ArrayList(); if(root=...
分类:
其他好文 时间:
2015-06-13 07:35:26
阅读次数:
118
描述树的遍历即给出一个指向树的指针,访问树中的每一个节点。树的遍历有三种基本遍历方式,分别是前序(preorder)、中序(inorder)、后序(postorder)。...
分类:
其他好文 时间:
2015-06-12 19:28:02
阅读次数:
143
题目:输入一个整数数组,实现一个函数中调整该数组中数字的顺序,使得所有的奇数位于数组的前半部,所有偶数位于数组的后半部。思路:用两个指针p1和p2,分别指向数组的头和尾部,p1只向后移,p2只向前移。当满足p1using namespace std;void preorder(int* pdata,...
分类:
编程语言 时间:
2015-06-11 18:29:27
阅读次数:
176
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recursive soluti...
分类:
其他好文 时间:
2015-06-05 10:14:40
阅读次数:
158
Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3...
分类:
编程语言 时间:
2015-06-04 22:33:35
阅读次数:
133
This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut...
分类:
其他好文 时间:
2015-06-03 00:46:35
阅读次数:
131
This problem seems to be tricky at first glance. However, if you know Morris traversal, it is just the preorder case of Morris traversal and the code ...
分类:
其他好文 时间:
2015-06-03 00:42:17
阅读次数:
136
Given a binary tree, return the preorder traversal of its nodes’ values.For example:
Given binary tree {1,#,2,3},1
\
2
/
3return [1,2,3].Note: Recursive solution is trivial, could...
分类:
其他好文 时间:
2015-06-01 22:47:38
阅读次数:
128
Binary Tree Preorder Traversal:https://leetcode.com/problems/binary-tree-preorder-traversal/
Binary Tree Inorder Traversal :https://leetcode.com/problems/binary-tree-inorder-traversal/
Binary Tree Po...
分类:
其他好文 时间:
2015-06-01 22:45:30
阅读次数:
137