常用的哈希表结构
- 数组
- 集合(unordered_set)
- 映射(unordered_map)
集合 底层实现 是否有序 数值是否可以重复 能否更改数值 查询效率 增删效率 unordered_set 哈希表 无序 否 否 O(1) O(1) unordered_map 哈希表 key无序 key不可重复 key不可修改 O(1) O(1)
需要记住的用法:
创建
Set<Integer> set1= new HashSet<>(); //集合
HashMap<Node,Node>=new HashMap<cur,new Node(cur.value)>; //hashmap
int [ ] arr = new int [26];//简单常量数组
常用函数
set.add(i); //集合添加元素
set.stream().mapToInt(x->x).toArray() //集合转为数组
if(set1.contains( ) ) //判断集合中是否包含某元素
HashMap.put ( nums[ i ], i ); //数组元素放入哈希map <key,value>对应<数组元素,数组索引>
易错点
数组的条件判断:if (nums1==null || nums1.length==0){ }