[Lintcode] 66. Binary Tree Preorder Traversal
来源:互联网 发布:nginx搭建wss环境 编辑:程序博客网 时间:2024/06/05 17:34
给出一棵二叉树,返回其节点值的前序遍历。
public class Solution { /** * @param root: The root of binary tree. * @return: Preorder in ArrayList which contains node values. */ public List<Integer> preorderTraversal(TreeNode root) { Stack<TreeNode> stack = new Stack<TreeNode>(); List<Integer> result = new ArrayList<Integer>(); if (root == null) { return result; } stack.push(root); while (!stack.empty()) { TreeNode node = stack.pop(); result.add(node.val); if (node.right != null) { stack.push(node.right); } if (node.left != null) { stack.push(node.left); } } return result; }}
阅读全文
0 0
- [Lintcode] 66. Binary Tree Preorder Traversal
- lintcode: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
- Kali Linux 渗透测试:扫描漏洞
- jquery模拟点击事件
- 【python图像处理】python中定义的颜色
- softmax分类算法原理(用python实现)
- 简单理解Socket及TCP/IP、Http、Socket的区别
- [Lintcode] 66. Binary Tree Preorder Traversal
- PHP的错误处理机制
- active record关联(ruby on rails guides)
- [HTML] Meta http-equiv属性详解
- git的一些常用命令
- C++类,构造函数,利用友元判断2个类数据
- 入职第一天,上午完成JBOSS安装配置
- WIN7系统如何与虚拟机Ubuntu系统通过SSH沟通
- python