题目:二叉树的前序遍历
来源:互联网 发布:房租占收入比例 知乎 编辑:程序博客网 时间:2024/04/24 14:35
/*** 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.
*/
ArrayList<Integer> result = new ArrayList<>();
public ArrayList<Integer> preorderTraversal(TreeNode root) {
// write your code here
if(root==null) return result;
result.add(root.val);
if(root.left!=null){
preorderTraversal(root.left);
}
if(root.right!=null){
preorderTraversal(root.right);
}
return result;
}
}
0 0
- 题目:二叉树的前序遍历
- java二叉树的前序遍历
- 算法:二叉树的前序遍历
- 二叉树的前序遍历算法
- 二叉树的前序遍历
- LintCode -- 二叉树的前序遍历
- lintcode 二叉树的前序遍历
- 二叉树的前序遍历
- 二叉树的前序遍历
- lintcode,二叉树的前序遍历
- 二叉树的前序遍历
- 二叉搜索树的前序遍历
- LintCode-二叉树的前序遍历
- 二叉树的前序遍历
- 二叉树的前序遍历
- lintcode 二叉树的前序遍历
- 二叉树的前序遍历
- 二叉树的前序遍历
- UIScreen(屏幕)、UIWindow(画框)、UIView(画布)、didFinishLaunchingWithOptions、UIViewController各个方法的加载顺序
- 题目:二叉树的中序遍历
- [LeetCode] Ugly Number
- android sdk +adt+eclipse
- poj3625 Building Roads(最小生成树)
- 题目:二叉树的前序遍历
- ListView 滑动时数据重复错位解决
- Android第三讲——五大布局(UI)
- 《UNIX环境高级编程》笔记--线程的取消选项
- 题目:二叉树的后序遍历
- 滚动CollectionView控制PageControl实现分页浏览的效果
- 黑马程序员—IO流
- 在delphi中Char,PChar,PByte,Byte,String的相互转换示例
- 题目:二叉树的最大深度