[刷题]Binary Tree Preorder Traversal
来源:互联网 发布:plc编程培训机构 编辑:程序博客网 时间:2024/06/01 09:56
[LintCode]Binary Tree Preorder Traversal
答案
/** * 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: Preorder in ArrayList which contains node values. */ public ArrayList<Integer> preorderTraversal(TreeNode root) { // 2015-3-22 DFS ArrayList<Integer> rst = new ArrayList<>(); if (root == null) { return rst; } // divide ArrayList<Integer> left = preorderTraversal(root.left); ArrayList<Integer> right = preorderTraversal(root.right); // conquer rst.add(root.val); rst.addAll(left); rst.addAll(right); return rst; }}
0 0
- [刷题]Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- node.js的优势和劣势
- 二分答案
- 专注内容,形式次之,立帖为证
- 欢迎使用CSDN-markdown编辑器
- 【USACO3.3.2】商店购物 状态压缩动态规划
- [刷题]Binary Tree Preorder Traversal
- 追逐自己的梦想----------辅助制作第二十四课:寻路call的分析
- ViewPager的页面的加载和移除
- MFC(0)关于MFC中的界面与业务逻辑的分离
- 如何看待 TJ 宣布退出 Node.js 开发,转向 Go?
- 28、传感器
- Java_语法基础_i+++j该如何计算
- Android下Json数据解析
- C++二叉树类实现