LeetCode 432. All O`one Data Structure

几万年没做LeetCode的题了,更新一下。 https://leetcode.com/problems/all-oone-data-structure/description/ 这道题的思路是用一个双向链表(list)来存储一个以value排序的数据结构,使用哈希表(unordered_map)来存储key到链表iterator的映射: 需要注意特殊处理value=1的Node的情况。 代码写得比较毛糙,但是确实是O(1)的复杂度,如果要优化的话map的插入可以用emplace()之类的。 注意:除了value=1的节点,其余节点的keys为空的时候要把该节点删除掉,否则getMaxKey()和getMinKey()就需要O(n)的遍历操作了。

     

LeetCode 278. First Bad Version

做点简单的题目练练手,最近天天在写Scope脚本,都快忘记怎么写其他代码了。 吐槽一下垃圾长城宽带,上LeetCode都要自己开代理,不然根本加载不了 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2,
Continue reading LeetCode 278. First Bad Version

LeetCode 217. Contains Duplicate

题目:https://leetcode.com/problems/contains-duplicate/ 思路:弄个哈希表啊或者现成的用哈希(或者XX树)的容器就行了 代码: