Monday, January 16, 2017

算法小结--Desgin集合

OO/Class 设计
» 157.158. Read N Characters Given Read4 I/ II - Call multiple times F家
第二题考class variable概念,一个obj的class var value是会被keep住的
http://rainykat.blogspot.com.tr/2017/01/leetcodef-157158-read-n-characters.html 
»  341. Flatten Nested List Iterator (Recursion) G家F家
Use recursion to traverse the nested list.
http://rainykat.blogspot.com/2017/02/leetcodegf-341-flatten-nested-list.html
» 146. LRU Cache(HashMap + Doubly LinkedList) 各大家
http://rainykat.blogspot.com/2017/02/leetcode-146-lru-cachehashmap-doubly.html 
» 398. Random Pick Index(Reservoir Sampling - Random F家
http://rainykat.blogspot.com/2017/01/leetcodef-398-random-pick-indexdesgin.html 
» 380. Insert Delete GetRandom O(1) (Map + List + Random 各大家
http://rainykat.blogspot.com/2017/02/leetcode-380-insert-delete-getrandom-o1.html 

➤Trie (use for prefix tree, eg: string match, spell check)
Complexity: O(M=key_length) for insertion & search, M is the length of key
                    Space: O(alphabet(26)*M*N) N is number of keys in trie
class TrieNode {
        //R links to node children
        private TrieNode[] links = new TrieNode[26];//simplified to save code
        private boolean isEnd;
    }
    private TrieNode root = new TrieNode();    
    public void insert(String word) {
        TrieNode node = root;

» 208. Implement Trie (Prefix Tree)
http://rainykat.blogspot.com/2017/01/leetcode-208-implement-trie-prefix-tree.html
» 211. Add and Search Word - Data structure design (Trie+ Backtracking)  F家
http://rainykat.blogspot.com/2017/01/leetcodef-211-add-and-search-word-data.html 

 ➤Queue应用
» 297. Serialize and Deserialize Binary Tree 各大家
http://rainykat.blogspot.com.tr/2017/01/leetcode-297-serialize-and-deserialize.html 
» 346. Moving Average from Data Stream (queue) G家
http://rainykat.blogspot.com/2017/01/leetcodeg-346-moving-average-from-data.html

No comments:

Post a Comment