随笔分类 -  哈希

摘要:problem : https://leetcode.com/problems/lru-cache/ 这道题的想法是维护三个数组,一个data记录实际的key-value数据,一个LRU的list记录LRU数据,一个pos记录每个数字所在的链表的位置。 对于LRU而言,每次访问到了出现过的数字,我们 阅读全文
posted @ 2020-03-19 21:42 fish1996 阅读(155) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/longest-well-performing-interval/ 将满足条件的视为+1,不满足的视为-1,计算前缀和。该题可以转换为计算和大于0的最小区间。 class Solution { public: int longestWPI( 阅读全文
posted @ 2020-02-08 00:53 fish1996 阅读(184) 评论(0) 推荐(0)
摘要:problem:https://leetcode.com/problems/rabbits-in-forest/ 值为n的可以和其它n + 1个值为n的成组,统计每个值出现的次数,看它们可以组成多少组相同颜色的兔子,然后乘以组中兔子个数。 阅读全文
posted @ 2019-08-04 17:44 fish1996 阅读(106) 评论(0) 推荐(0)
摘要:problem:https://leetcode.com/problems/permutation-in-string/ 这道题感觉几乎和Leetcode上另一题一模一样,昨天刚刷的:https://www.cnblogs.com/fish1996/p/11269526.html,就当签到题爽一爽了 阅读全文
posted @ 2019-07-31 20:57 fish1996 阅读(145) 评论(0) 推荐(0)
摘要:problem:https://leetcode.com/problems/find-all-anagrams-in-a-string 主要思路是维护两个hashmap,一个记录期望出现的字符,一个记录当前出现的字符。 当前出现的字符随着窗口滚动不停更新,每次移动窗口后,都判断当前窗口是否满足条件。 阅读全文
posted @ 2019-07-30 13:37 fish1996 阅读(272) 评论(0) 推荐(0)
摘要:problem:https://leetcode.com/problems/minimum-area-rectangle/ 使用哈希表,选取任意两点(视为矩形的两个对角),查找另外两个点是否存在,如果存在则更新最小面积矩阵。 时间复杂度O(N^2)。 阅读全文
posted @ 2019-07-29 20:25 fish1996 阅读(218) 评论(0) 推荐(0)