摘要: 很容易联想到 at most distinct k 等一连串sliding window的问题,但是真正做起来发现困难重重。 具体来说,通过sliding window我们的确可以得到一个个以a[i]结尾的,exactly k个不同元素的最长window。但是我们很难求出这样的window中一共有多 阅读全文
posted @ 2019-11-06 14:14 約束の空 阅读(214) 评论(0) 推荐(0) 编辑
摘要: Hashtable + BST 用hashtable保存key->Node,另外用一个set<Node>来根据freq和time进行排序,保证容量满时删除的是LFU的节点。 注意这里hashtable的value存的是Node,不是指针也不是set的iterator。因为用指针只能做到从set里删除 阅读全文
posted @ 2019-11-02 11:59 約束の空 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 下图是Java里的概念,其中 Hashtable 和 SynchronizedMap 都是对整个map加锁,所以多个thread没法同时修改。 ConcurrentHashMap 则允许多个thread同时访问不同的entry,即如果thread操作的key不同,这些thread是可以同时读写的。如 阅读全文
posted @ 2019-10-26 06:00 約束の空 阅读(200) 评论(0) 推荐(0) 编辑
摘要: The reader and writer processes share the following data structures: semaphore rw_mutex = 1; semaphore mutex = 1; int read_count = 0; The semaphores m 阅读全文
posted @ 2019-10-26 04:44 約束の空 阅读(443) 评论(0) 推荐(0) 编辑
摘要: Quicksort not stable in place faster than other sorting algorithms for small data set Quickselect quickselect is a selection algorithm to find the kth 阅读全文
posted @ 2019-10-26 02:48 約束の空 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Merge Sort stable sort most common implementation does not sort in place external merge sort Time Complexity: O(nlogn) 阅读全文
posted @ 2019-10-26 02:27 約束の空 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Reservoir sampling is a family of randomized algorithms for randomly choosing k samples from a list of n items, where n is either a very large or unkn 阅读全文
posted @ 2019-10-21 02:51 約束の空 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Hash Function: A function that converts a given big phone number to a small practical integer value. The mapped integer value is used as an index in h 阅读全文
posted @ 2019-10-15 10:42 約束の空 阅读(245) 评论(0) 推荐(0) 编辑
摘要: DP 由于括号匹配的特殊性,合法的括号匹配最后一定是')',因此我们可以记录以每个字符为结尾的最长括号匹配数。 dp[i] = 以s[i]结尾的最长括号匹配数 递推公式有两种可能: 1. 如果s[i-1]=='(',dp[i] = dp[i-2] + 2 2. 如果s[i-1]==')',我们可以通 阅读全文
posted @ 2019-10-15 04:38 約束の空 阅读(118) 评论(0) 推荐(0) 编辑
摘要: Operating systems often distinguish between counting and binary semaphores. The value of a counting semaphore can range over an unrestricted domain. T 阅读全文
posted @ 2019-10-14 07:43 約束の空 阅读(422) 评论(0) 推荐(0) 编辑