
哈希
洞阳
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode 291. Word Pattern II和290. Word Pattern
用stringstream分割字符串。原创 2025-06-20 19:01:27 · 309 阅读 · 0 评论 -
491. Non-decreasing Subsequences
由于题目保证-100<=nums[i]<=100,去重的哈希表也可以用数组来实现。原创 2025-05-28 23:51:04 · 209 阅读 · 0 评论 -
146. LRU Cache
【代码】146. LRU Cache。原创 2025-05-23 23:39:26 · 400 阅读 · 0 评论 -
138. Copy List with Random Pointer
问题的关键是,random指针指向的是原链表的结点,这个原链表的结点对应哪一个新链表的结点呢?有两种办法。一是用哈希表。另一种是复制原链表的每一个结点,并将新结点接在原结点的后面组成一个长度加倍的链表,这样原结点的直接后继就是该原结点对应的新结点。原创 2025-05-21 11:23:47 · 568 阅读 · 0 评论 -
leetcode 438. Find All Anagrams in a String和30. Substring with Concatenation of All Words
【代码】leetcode 438. Find All Anagrams in a String和30. Substring with Concatenation of All Words。原创 2025-05-18 16:01:12 · 235 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters
【代码】leetcode 3. Longest Substring Without Repeating Characters。原创 2025-05-18 01:04:12 · 270 阅读 · 0 评论 -
128. Longest Consecutive Sequence
如果n-1存在于数组中,则以n开头的连续序列可以忽略掉,因为以n-1开头的连续序列的长度肯定至少比以n开头的连续序列长1个元素。然后利用哈希表查询元素是否在数组中。第7行遍历hash_table而不是遍历原始数组,可以避免存在大量重复元素的情况下运行超时。原创 2025-03-19 23:17:40 · 212 阅读 · 0 评论 -
leetcode 217. Contains Duplicate和219. Contains Duplicate II和220. Contains Duplicate III
用滑动窗口+哈希表解决。假如当前遍历到了第i个元素,哈希表维护【i-k,i】这个长度为k+1的滑动窗口范围内的元素。排序后,相等的元素必然相邻。原创 2025-05-14 17:53:15 · 380 阅读 · 0 评论 -
leetcode 205. Isomorphic Strings、290. Word Pattern、890. Find and Replace Pattern
【代码】leetcode 205. Isomorphic Strings和290. Word Pattern。原创 2025-05-14 15:08:29 · 450 阅读 · 0 评论 -
leetcode 454. 4Sum II
【代码】leetcode 454. 4Sum II。原创 2025-05-11 23:45:32 · 323 阅读 · 0 评论 -
leetcode 349. Intersection of Two Arrays
如图所示unordered_set可以直接用vector构造。也可以用unordered_set。原创 2025-05-10 15:17:36 · 277 阅读 · 0 评论