Binary Tree Preorder Traversal
来源:互联网 发布:mash up软件下载 编辑:程序博客网 时间:2024/05/19 16:35
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> preorderList = new ArrayList<Integer>(); if(null == root) return preorderList; Stack<TreeNode> stack = new Stack<TreeNode>(); stack.add(root); while(!stack.empty()) { TreeNode topStackNode = stack.pop(); preorderList.add(topStackNode.val); if(topStackNode.right != null) stack.push(topStackNode.right); if(topStackNode.left != null) stack.push(topStackNode.left); } return preorderList; }}
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
- php为Apache指定工作目录(虚拟目录)
- 道路模型--linear-parabolic model
- 事件监听机制
- SpringMVC-05 处理模型数据
- greenDAO 使用初体验
- Binary Tree Preorder Traversal
- 宁早不晚,美国想要汽车之间彼此对话
- 什么是回文数
- 微软100题(3) 最大子数组和
- [Linux]内存共享
- Leetcode Count and Say
- 使用git
- java中的注释
- 排序汇总