leetcode Ch4-Binary Tree & BFS & Divide/Conquer
2015-06-19 10:16
597 查看
一、
1. Lowest Common Ancestor
View Code
参见 ref 十五
Binary Tree Serialization
===================================================
对于n个数的数组,一个数x如果从左往右数是第k个数,那么从右往左数的话是第(n - k + 1)个数。
1. Lowest Common Ancestor
class BSTIterator { public: BSTIterator(TreeNode* root) { pushAll(root); } bool hasNext() { return (!myStack.empty()); } int next() { TreeNode* tmp = myStack.top(); myStack.pop(); pushAll(tmp->right); return tmp->val; } private: stack<TreeNode*> myStack; void pushAll(TreeNode* node); }; void BSTIterator::pushAll(TreeNode* node) { while (node != NULL) { myStack.push(node); node = node->left; } } /** * Your BSTIterator will be called like this: * BSTIterator i = BSTIterator(root); * while (i.hasNext()) cout << i.next(); */
View Code
Remove Node in Binary Search Tree
Binary Tree Maximum Path Sum参见 ref 十五
Binary Tree Serialization
===================================================
对于n个数的数组,一个数x如果从左往右数是第k个数,那么从右往左数的话是第(n - k + 1)个数。
相关文章推荐
- [SoapUI] SoapUI download address
- UITextView 单行垂直居中显示
- easyUI如何选择使用指定的locale
- StringBuilder类和StringBuffer类,线程安全问题和选择
- IOS中UIScrollView和UIPageControl的联合运用
- SQL Server 系统表介绍:sys.dm_exec_requests
- IQueryable和IEnumerable的区别
- request 获取参数
- 为Angular-UEditor增加工具栏属性
- NGUI 的ScrollView如何让item居中
- 【Android开发经验】Android举UI设计经验
- 【iOS】UIStackView官方文档翻译
- SQL Server查询计划sys.dm_exec_text_query_plan
- UGUI 实现文本打字效果
- UITableView学习笔记
- Leetcode Implement stack using queues
- [Druid:数据库连接池] removeAbandoned 功能引发的血案 避免单业务执行时间超时
- UIScrollView的使用大全
- leetcode 225: Implement Stack using Queues
- EasyUI上传图片,前台预览,后台读取