Sliding window(已看,已理解,未写)
http://leetcode.com/2011/01/sliding-window-maximum.html
方法1:暴力解
方法2:for 循环内每一步计算的都是上一步的window的最大值,所以最后一个window得单独计算
注意: priority_queue每次push或者pop都会重新生成最大/小值在开头
方法3:用双向链表,queue里存的是element的index。当前的最大值永远在最前,不用考虑比最大值小的值。每当插入一个新的值,pop掉所有比它小的值。之后在对比当前最大值是否在范围(window)内
Wednesday, October 29, 2014
Sunday, October 12, 2014
Notes on Notes -- Chapter 2, 3, 4*
chapter 2
设定dummy
----------
chapter 3
--------
chapter4
trie -- implementation
http://en.wikipedia.org/wiki/Trie
heap
priority queue
graph -- implementation
http://www.cs.bu.edu/teaching/c/graph/linked/
设定dummy
----------
chapter 3
Tower of Hanoi
iterative solution
http://en.wikipedia.org/wiki/Tower_of_Hanoi--------
chapter4
trie -- implementation
http://en.wikipedia.org/wiki/Trie
heap
priority queue
graph -- implementation
http://www.cs.bu.edu/teaching/c/graph/linked/
Dijkstra's algorithm
greedy
Check if a graph has a cycle
undirected: use DFS
Find the immediate right neighbor of the given node, with parent links given, but without root node.( Ebay interview question)
Word Ladder II
undirected: use DFS
directed: use Topological sorting
lowest common ancestor
http://leetcode.com/2011/07/lowest-common-ancestor-of-a-binary-tree-part-i.html
lowest common ancestor
http://leetcode.com/2011/07/lowest-common-ancestor-of-a-binary-tree-part-i.html
Find the immediate right neighbor of the given node, with parent links given, but without root node.( Ebay interview question)
Word Ladder II
Subscribe to:
Posts (Atom)