/**
* 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的更多相关文章

  1. 49. leetcode 94. Binary Tree Inorder Traversal

    94. Binary Tree Inorder Traversal    二叉树的中序遍历 递归方法: 非递归:要借助栈,可以利用C++的stack

  2. [leetcode] 94. Binary Tree Inorder Traversal 二叉树的中序遍历

    题目大意 https://leetcode.com/problems/binary-tree-inorder-traversal/description/ 94. Binary Tree Inorde ...

  3. 二叉树前序、中序、后序非递归遍历 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 前序的非递归遍历:用堆来实现 如果把这个代码改成先向堆存储左节点再存储右节点,就变成了每一行从右向左打印 如果用队列替代堆,并且 ...

  4. 刷题94. Binary Tree Inorder Traversal

    一.题目说明 题目94. Binary Tree Inorder Traversal,给一个二叉树,返回中序遍历序列.题目难度是Medium! 二.我的解答 用递归遍历,学过数据结构的应该都可以实现. ...

  5. Construct Binary Tree from Preorder and Inorder Traversal

    Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...

  6. 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 ...

  7. 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 ...

  8. 【题解二连发】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 ...

  9. LeetCode: Construct Binary Tree from Preorder and Inorder Traversal 解题报告

    Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...

随机推荐

  1. 学android:直接用jdk来helloworld

    本文稍稍了解下java的编译机制, 以及试试纯粹的jdk来helloworld 在jdk安装位置的bin 目录下看看jdk的工具 有许多的jdk的工具吧,当然,和bin同级的目录下还有jre, lib ...

  2. LAMP简易安装

    看,老鸟绕道–LAMP简易安装 导读 LAMP是企业中最常用的服务,也是非常稳定的网站架构平台.其中L-指的是Linux,A-指的是Apache,m-指的是mysql或者marriDB,p-php.相 ...

  3. 2015.10.15night

    #include<stdio.h> main() { int x,y; scanf("%d",&x); if(x>0)y=1; else {if(x< ...

  4. 《Android深度探索HAL与驱动开发》第四章阅读心得

     Android源代码包含了很多内容,可以实现拍照.计算机.日历.相册.拨号器等功能.配置Android源代码下载环境需要如下几步: (1)创建一个用于存放下载脚本文件的目录:  (2)下载repo脚 ...

  5. Angular.JS + Require.JS + angular-async-loader 来实现异步加载 angular 模块

    传统的 angular 应用不支持异步加载模块,必须在 module 启动的时候,所有模块必须预加载进来. 通过使用 angular-async-loader 库,我们可以使用 requirejs 等 ...

  6. 3.基础点的移动web

    1.移动端的屏幕适配 在Web开发中可以使用px(像素).em.pt(点).in(英寸).cm(厘米)做为长度单位,我们最常用px(像素)做为长度单位. 我们可以将上述的几种长度单位划分成相对长度单位 ...

  7. tomcat7 Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config. The configuration may be corrupt or incomplete

    参考连接: http://lucasterdev.altervista.org/wordpress/2012/05/12/could-not-load-the-tomcat-server-config ...

  8. ADB命令详解

    一.adb介绍 ADB的全称为Android Debug Bridge,字面意思就是安卓调试桥接,简单点说,它是Android系统提供的一套工具,通过它,我们可以在电脑上建立一个连接到手机的通道,然后 ...

  9. fdisk,mount.label

    ########fdisk ll /dev/sda* df -TH fdisk -cul fdisk -cu ~~n~~p~~+1G~~ partx -a /dev/sda ########EXT4 ...

  10. c#-1 数据结构 定义相关 界面交互数据 Model层

    1.时间用Nullable<UInt32> 除了最初时间用DateTime TimeSpan不行. 2.其他元素也用Nullable<UInt32> 3.list集合数据绑定类 ...