码迷,mamicode.com
首页 > 其他好文 > 详细

哈希表

时间:2020-03-13 20:39:03      阅读:43      评论:0      收藏:0      [点我收藏+]

标签:nta   get   更新   重复元素   boolean   出现   ash   set   常见   

1、 hashset

add(value)  插入

contains(value)  判断是否存在  boolean

remove(value)  移除

MyHashSet hashSet = new MyHashSet();
hashSet.add(1);         
hashSet.add(2);         
hashSet.contains(1);    // 返回 true
hashSet.contains(3);    // 返回 false (未找到)
hashSet.add(2);          
hashSet.contains(2);    // 返回 true
hashSet.remove(2);          
hashSet.contains(2);    // 返回  false (已经被删除)

常见题:
1、 判断是否存在重复元素 

2、 只出现一次的数字

 

 

 

2、 hashmap  映射

put(key ,value) 插入, 如果存在对应的key  更新value

get(key)   返回 key对应的value  如果没有 返回 -1;

remove(key)   如果存在对应的value  ,删除value;

 

哈希表

标签:nta   get   更新   重复元素   boolean   出现   ash   set   常见   

原文地址:https://www.cnblogs.com/try-chi/p/12487668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!