摘要: 键值对想到hashmap, 增删节点考虑链表, + 头尾节点, 因此要构造相应的类 双向链表需要头尾节点 The problem can be solved with a hashtable that keeps track of the keys and its values in the dou 阅读全文
posted @ 2017-07-26 21:44 apanda009 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 为啥用栈, 数组相对顺序不能变, 要找第一个比当前元素小的元素, 或大的元素, 同84. Largest Rectangle in Histogram 同84. Largest Rectangle in Histogram 在数组后面加"0", 这些操作都是为了遍历所有的元素, 有的不需要遍历所有的 阅读全文
posted @ 2017-07-26 21:18 apanda009 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 遍历, 没用到bst的性质: 递归 阅读全文
posted @ 2017-07-26 15:19 apanda009 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Iterative做法 分治法: Recursion做法: 阅读全文
posted @ 2017-07-26 13:24 apanda009 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 用bst的性质遍历就行了: Just walk down from the whole tree's root as long as both p and q are in the same subtree (meaning their values are both smaller or both 阅读全文
posted @ 2017-07-26 10:36 apanda009 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 分治法, 自己画个简图(三个, 两个节点), 遍历一下 会写树的高度, 在树的高度上加了个判断而已.别忘了左子树和右子树也是要查的 分治法主要在如何设计返回值, 和题意与返回值的转化, 递归出口1(判空), 最后的节点的出口2(或许加判断等), 分, 合: 将分好的左右节点作为单个节点, 进行题意的 阅读全文
posted @ 2017-07-26 09:26 apanda009 阅读(130) 评论(0) 推荐(0) 编辑