(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 ...
随机推荐
- robotframework接口测试初探2
python这个requests模块常被用来测试接口.使用RequestLibrary库测试之前,先来看下这个模块是怎样使用的 最简单的调用是 r=requests.get("http:// ...
- extJS起步
万事开头难,不过还好有解决办法——参考如下文章 http://blog.csdn.net/leimengyuanlian/article/details/18748599 可以快速搭建好eclipse ...
- rtmp转m3u8
不是所有的地址改成这样都能播 需要自己测试 先说一下rtmp的其中rtmp的常见的差不多是3种 1.一种是wowza服务器的 比如这个地址rtmp://116.55.245.135:8096/live ...
- Android之ProgressBar初步应用
这里利用 ProgressBar 即时显示下载进度. 途中碰到的问题: 1.主线程中不能打开 URL,和只能在主线程中使用 Toast 等 2.子线程不能修改 UI 3.允许网络协议 4.暂停下载和继 ...
- 1.Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
- Servlet-RequestDispatcher.forward方法
forward方法与Include方法非常相似,但有5点不同 1,在调用forward方法之前,输出缓冲区的数据会被清空,也就是说,在使用forward方法进行请求转发时,只可能输出别转发的web资源 ...
- input 边框颜色
border 的属性 有三个 border:5px solid red; 如果上述值缺少一个没有关系,例如border:#FF0000;是允许的. 分别对应:border-width, border- ...
- UIPickerView控件中自定义展示的字体大小及样式
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger) ...
- 00 alv抬头等
*&---------------------------------------------------------------------* *& Report ZHJ_TEST0 ...
- C++语法
http://stackoverflow.com/questions/4269034/what-is-the-meaning-of-prepended-double-colon