Leetcode 706 設計雜湊對映 C

2021-10-08 14:58:51 字數 1395 閱讀 6971

不使用任何內建的雜湊表庫設計乙個雜湊對映

具體地說,你的設計應該包含以下的功能

myhashmap hashmap = new myhashmap();

hashmap.put(1, 1);

hashmap.put(2, 2);

hashmap.get(1); // 返回 1

hashmap.get(3); // 返回 -1 (未找到)

hashmap.put(2, 1); // 更新已有的值

hashmap.get(2); // 返回 1

hashmap.remove(2); // 刪除鍵為2的資料

hashmap.get(2); // 返回 -1 (未找到)

注意:

方法與705題一致

詳細過程見**

class

myhashmap};

vector> dataset;

int len =

200;

/** initialize your data structure here. */

myhashmap()

/** value will always be non-negative. */

void

put(

int key,

int value)

else

else

} now-

>next =

newnode

(key,value);}

}}intget

(int key)

if(now ==

null

)return-1

;return now-

>value;

}void

remove

(int key)

else

if(now-

>next) now-

>next = now-

>next-

>next;}}

}};/**

* your myhashmap object will be instantiated and called as such:

* myhashmap* obj = new myhashmap();

* obj->put(key,value);

* int param_2 = obj->get(key);

* obj->remove(key);

*/

leetcode 706 設計雜湊對映

不使用任何內建的雜湊表庫設計乙個雜湊對映 具體地說,你的設計應該包含以下的功能 put key,value 向雜湊對映中插入 鍵,值 的數值對。如果鍵對應的值已經存在,更新這個值。get key 返回給定的鍵所對應的值,如果對映中不包含這個鍵,返回 1。remove key 如果對映中存在這個鍵,刪...

LeetCode 706 設計雜湊對映

不使用任何內建的雜湊表庫設計乙個雜湊對映 具體地說,你的設計應該包含以下的功能 put key,value 向雜湊對映中插入 鍵,值 的數值對。如果鍵對應的值已經存在,更新這個值。get key 返回給定的鍵所對應的值,如果對映中不包含這個鍵,返回 1。remove key 如果對映中存在這個鍵,刪...

leetcode 706 設計雜湊對映

706.設計雜湊對映 不使用任何內建的雜湊表庫設計乙個雜湊對映 具體地說,你的設計應該包含以下的功能 put key,value 向雜湊對映中插入 鍵,值 的數值對。如果鍵對應的值已經存在,更新這個值。get key 返回給定的鍵所對應的值,如果對映中不包含這個鍵,返回 1。remove key 如...