94. Binary Tree Inorder Traversal
来源:互联网 发布:火爆网络的ann艳照 编辑:程序博客网 时间:2024/06/03 17:03
problem:
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree [1,null,2,3]
,
1 \ 2 / 3
return [1,3,2]
.
Note: Recursive solution is trivial, could you do it iteratively?
solution:
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> rei;
stack<TreeNode *> undone;
TreeNode *pCurrent = root;
while (!undone.empty()|| pCurrent != NULL)
{
if (pCurrent->left != NULL)
{
undone.push(pCurrent);
pCurrent = pCurrent->left;
}
else
{
pCurrent = undone.top();
rei.push_back(pCurrent->val);
pCurrent = pCurrent->right;
}
}
return rei;
}
};
阅读全文
0 0
- 94. Binary Tree Inorder Traversal
- 94.Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94.Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 94. Binary Tree Inorder Traversal
- 用于单分支控制的条件语句
- JUC基础概述
- hdoj 3535 AreYouBusy(混合背包)
- XListView—Android开源项目
- 四大组件之contentProvider内容监听者
- 94. Binary Tree Inorder Traversal
- 基础算法 之 BFS & DFS
- ios-__autoreleasing修饰符
- 【其他】我整理了一个书单
- PHP操作mongo数据库
- Hadoop与Spark算法分析(三)——矩阵乘法
- 《零基础入门学习Python》学习笔记1
- Consul 是什么
- Zookeeper_神奇的动物在哪里?