(Tree)94.Binary Tree Inorder Traversal
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> res=new ArrayList();
ArrayDeque<TreeNode> stack=new ArrayDeque(); //双端队列的使用
TreeNode tmp=root;
while(!stack.isEmpty() || tmp!=null){ //双判断
if(tmp!=null){
stack.push(tmp);
tmp=tmp.left;
}
else{
tmp=stack.pop();
res.add(tmp.val);
tmp=tmp.right;
}
}
return res;
}
}
(Tree)94.Binary Tree Inorder Traversal的更多相关文章
- 49. leetcode 94. Binary Tree Inorder Traversal
94. Binary Tree Inorder Traversal 二叉树的中序遍历 递归方法: 非递归:要借助栈,可以利用C++的stack
- [leetcode] 94. Binary Tree Inorder Traversal 二叉树的中序遍历
题目大意 https://leetcode.com/problems/binary-tree-inorder-traversal/description/ 94. Binary Tree Inorde ...
- 二叉树前序、中序、后序非递归遍历 144. Binary Tree Preorder Traversal 、 94. Binary Tree Inorder Traversal 、145. Binary Tree Postorder Traversal 、173. Binary Search Tree Iterator
144. Binary Tree Preorder Traversal 前序的非递归遍历:用堆来实现 如果把这个代码改成先向堆存储左节点再存储右节点,就变成了每一行从右向左打印 如果用队列替代堆,并且 ...
- 刷题94. Binary Tree Inorder Traversal
一.题目说明 题目94. Binary Tree Inorder Traversal,给一个二叉树,返回中序遍历序列.题目难度是Medium! 二.我的解答 用递归遍历,学过数据结构的应该都可以实现. ...
- Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...
- 36. Construct Binary Tree from Inorder and Postorder Traversal && Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal OJ: https://oj.leetcode.com/problems/cons ...
- LeetCode:Construct Binary Tree from Inorder and Postorder Traversal,Construct Binary Tree from Preorder and Inorder Traversal
LeetCode:Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder trav ...
- 【题解二连发】Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree from Preorder and Inorder Traversal
LeetCode 原题链接 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode Construct Binary ...
- LeetCode: Construct Binary Tree from Preorder and Inorder Traversal 解题报告
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...
随机推荐
- 【转】家庭wifi覆盖指导
网址:家庭wifi覆盖指导 私以为,目前民用 wifi 路由器市场已经完全走上了邪路.天线越来越大,发射功率越做越高.都敢冒着法律的风险使用大大超过 100mW 的发射功率了.且不论巨大的发射功率可能 ...
- Django project structure: how does static folder, STATIC_URL, STATIC_ROOT work
So I've been messing up with Django(1.6+) project setting for quite sometime, this is what i finally ...
- js jquery实时计算输入字符
在项目中需要倒还可以输入多少字符
- 图片在ie8浏览器打不开,其他浏览器都可以打开的问题
问题描述: 1.图片在IE8浏览器打不开,但是IE8以上及其他浏览器均可以打开: 2.同一网站,其他图片可以在IE8浏览器打开 解决办法: 1.图片的颜色模式是CMYK模式,应改为RGB模式 2.修改 ...
- Python实例1
1.有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 错解: 正解: 源码: #!/usr/bin/python for i in range(1,5): for j in ...
- Android——通讯录
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- JavaScript分离代码理解
window.onload=prepareLinks; //页面加载触发onload事件 function prepareLinks(){ //定义函数 var links=document.getE ...
- [课程设计]Scrum 1.3 多鱼点餐系统开发进度
[课程设计]Scrum 1.3 多鱼点餐系统开发进度 Scrum 1.3 多鱼点餐系统开发进度 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追 ...
- IE弹出窗口显示URL地址栏
工具-->Internet 选项-->安全-->自定义级别-->允许网站打开没有地址栏或状态栏的窗口-->禁止
- POSIX正则表达式
POSIX正则表达式规范 参考:http://en.wikipedia.org/wiki/Regular_expression POSIX正则表达式分为Basic Regular Expression ...