Binary Tree Preorder Traversal
来源:互联网 发布:淘宝上可信的澳洲代购 编辑:程序博客网 时间:2024/06/07 22:45
这么简单的基本功能不能一次过啊!!!
/** * 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> list = new LinkedList<>(); if (root == null) { return list; } Stack<TreeNode> stack = new Stack<>(); stack.push(root); while (!stack.isEmpty()) { TreeNode node = stack.pop(); //list.add(node); list.add(node.val); if (node.right != null) { stack.push(node.right); } if (node.left != null) { stack.push(node.left); } } return list; }}
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
- 安卓NoTitleBar的style下关于switch的坑
- 【httplistener监听获取Post请求参数】
- 浅谈Android系统进程间通信(IPC)机制Binder中的Server和Client获得Service Manager接口之路
- 五种 JSP页面跳转方法详解
- Andrew NG 《machine learning》week 4,class1 —Motivations
- Binary Tree Preorder Traversal
- Android中的内存泄露问题
- UITableView默认选中第一个cell
- 三星上传问题解答(特别是2014年7月1日后新注册的开发者)
- 关于springmvc的跨域问题
- 过滤DataTable数据的Select()方法
- java和jsp四舍五入问题
- gcc -static 命令
- c/c++中float和double类型的存储