Title:Design HashSet 705
Difficulty:Easy
原题leetcode地址: https://leetcode.com/problems/design-hashset/
1. 见代码
时间复杂度:O(1)。
空间复杂度:O(n),申请数组。
public class HashTable0705DesignHashSet {
/**
* main
* @param args
*/
public static void main(String args[]) {
}
boolean[] map = new boolean[1000005];
/** Initialize your data structure here. */
public HashTable0705DesignHashSet() {
}
public void add(int key) {
map[key] = true;
}
public void remove(int key) {
map[key] = false;
}
/** Returns true if this set contains the specified element */
public boolean contains(int key) {
return map[key] == true;
}
}