![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
hash
程序喵阿呆
道济天下,智周万物
展开
-
LeetCode 146 LRU算法-hash+双链表、unorder_map
第二种解法:利用unordered_map本身进行匹配,实验表明,unordered_map是头插法,并且没有rbegin()迭代器,使用end()达不到想要的效果,所以每次删除数据冷的结点,需要遍历整个hash表,到第17个case通过不了。第一种解法:hash+双向链表。原创 2022-01-08 23:33:43 · 247 阅读 · 0 评论 -
HashMap的使用
尝试自己写一个HashMap,统计一个数组中各个元素的个数,数组设置的比较小,后续再优化,冲突的时采用地址链接法。#include<stdio.h>typedef struct Node{ int val; int count; struct Node *next;}node;#define seed 7node *p[seed] = {NULL};int add_hash(int key){ int idx = key * key % seed; if(p[id原创 2021-08-18 23:41:31 · 161 阅读 · 0 评论