lintcode:二叉树的中序遍历
来源:互联网 发布:淘宝司法拍卖怎么样 编辑:程序博客网 时间:2024/04/30 15:16
/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */public class Solution { /** * @param root: The root of binary tree. * @return: Inorder in ArrayList which contains node values. */ public ArrayList<Integer> inorderTraversal(TreeNode root) { // write your code here ArrayList<Integer> res=new ArrayList<Integer>();//记录遍历路径 ArrayList<TreeNode> p=new ArrayList<TreeNode>();//记录节点 while(root!=null||p.size()!=0){ while(root!=null){ p.add(root); root=root.left; }//如果root不为空一直像左走到底,root指向最左边的节点。若为空,则退到上一个节点 root=p.get(p.size()-1); p.remove(p.size()-1);//取得元素并删除 res.add(root.val); root=root.right; } return res; }}中序遍历:左 中 右
0 0
- LintCode -- 二叉树的中序遍历
- lintcode 二叉树的中序遍历
- lintcode:二叉树的中序遍历
- lintcode,二叉树的中序遍历
- LintCode-二叉树的中序遍历
- Lintcode 二叉树的中序遍历
- Lintcode 二叉树的中序遍历
- LintCode 二叉树的中序遍历
- 二叉树的中序遍历-LintCode
- lintcode二叉树的中序遍历
- LintCode 二叉树的中序遍历
- lintcode--二叉树的中序遍历
- lintcode--二叉树的中序遍历
- lintcode-二叉树的中序遍历(非递归)-67
- Lintcode 67 二叉树的中序遍历
- lintcode——二叉树的中序遍历
- lintcode 67 二叉树的中序遍历
- LintCode 68 二叉树的中序遍历
- 从极光币一窥加密数字资产普及化的重要性
- 【PAT甲级】1060. Are They Equal (25)
- 第九周 项目四 【广义表算法库及应用 2】
- Android Studio 2.2之布局编辑器
- Dominik Göddeke -- GPGPU::Basic Math Tutorial
- lintcode:二叉树的中序遍历
- 用c语言实现的FFT
- laravel 中 phpunit的使用
- J2SE第二章——Java基本语法(二)
- 设计模式学习笔记-观察者模式
- Ubuntu 16.04 解压缩zip文件中文乱码
- 世界65%银行在3年内将采用区块链技术
- HDU2191悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- 如何使用arraylist对存放class中某个元素进行排序