Binary Tree Traversal
来源:互联网 发布:护国神翼wings知乎 编辑:程序博客网 时间:2024/06/03 09:17
Binary Tree Preorder Traversal
public class Solution { public ArrayList<Integer> preorderTraversal(TreeNode root) { ArrayList<Integer> res = new ArrayList<Integer>(); if(root == null){ return res; } res.add(root.val); res.addAll(preorderTraversal(root.left)); res.addAll(preorderTraversal(root.right)); return res; }}
Binary Tree Inorder Traversal
public class Solution { public ArrayList<Integer> inorderTraversal(TreeNode root) { ArrayList<Integer> res = new ArrayList<Integer>(); if(root == null){ return res; } res.addAll(inorderTraversal(root.left)); res.add(root.val); res.addAll(inorderTraversal(root.right)); return res; }}
Binary Tree Postorder Traversal
public class Solution { public ArrayList<Integer> postorderTraversal(TreeNode root) { ArrayList<Integer> res = new ArrayList<Integer>(); if(root == null){ return res; } res.addAll(postorderTraversal(root.left)); res.addAll(postorderTraversal(root.right)); res.add(root.val); return res; }}
0 0
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Inorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Preorder Traversal
- 在HCI层ACL Connection的建立
- c++标准IO流
- class卸载、热替换和Tomcat的热部署的分析
- 在HCI层看从inquiry的整个过程
- 字节流字符流的区别
- Binary Tree Traversal
- vijos1763Wormhole
- 用FTS分析蓝牙数据包
- 黑马程序员-我所知道的两种做动态字的方法
- rsync服务器架设(数据同步|文件增量备份)
- Bluetooth在andriod下的开发基本操作
- 屌丝程序员在夏始春末拍的罗曼史之夏婚系列---结婚了
- 线性表-顺序队列(循环队列)
- 一个关于在页面写javaScript传值的问题