94. Binary Tree Inorder Traversal
2016-04-03 15:16
344 查看
/** * 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<Integer>(); Stack<TreeNode> st=new Stack<TreeNode>(); TreeNode temp=root; while(temp!=null||!st.isEmpty()) { // 将所有的节点都入栈,并且按照中序遍历的逆序进行入栈 if(temp==null) { temp=st.pop(); res.add(temp.val); temp=temp.right; } else { st.push(temp); temp=temp.left; } } return res; } }
相关文章推荐
- Nginx reload的时候出现的问题/usr/local/nginx/logs/nginx.pid
- SQLite 命令
- 使用ngrok让微信公众平台通过80端口访问本机
- oracle job
- Tomcat配置参数详解
- 线程池ThreadPoolExecutor
- JQuery日期插件datepicker的使用
- cacti监控思科路由器网卡流量 推荐
- 构造函数的理解和应用场景
- jboss tomcat 配置https请求方式
- Java十进制转二进制,递归算法
- UDEV SCSI Rules Configuration for ASM in Oracle Linux 5, 6 and 7
- 20160403_C++初始化列表与赋值
- Android Studio 1.5.1 JNI 编程
- ARP与RARP详细解析
- [LeetCode 7] Reverse Integer
- #1037 : 数字三角形
- UVa 1673 str2int
- 【dotnet跨平台】最新版dotnet-cli下的ASP.NET Core和asp.net mvc【RC2尝鲜】
- 4.Windows Server2012 R2里面部署 MVC 的网站