Design a HashSet without using any built-in hash table libraries.

Implement MyHashSet class:


	void add(key) Inserts the value key into the HashSet.
	bool contains(key) Returns whether the value key exists in the HashSet or not.
	void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.


&nbsp;
Example 1:

Input
["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"]
[[], [1], [2], [1], [3], [2], [2], [2], [2]]
Output
[null, null, null, true, false, null, true, null, false]

Explanation
MyHashSet myHashSet = new MyHashSet();
myHashSet.add(1);      // set = [1]
myHashSet.add(2);      // set = [1, 2]
myHashSet.contains(1); // return True
myHashSet.contains(3); // return False, (not found)
myHashSet.add(2);      // set = [1, 2]
myHashSet.contains(2); // return True
myHashSet.remove(2);   // set = [1]
myHashSet.contains(2); // return False, (already removed)

&nbsp;
Constraints:


	0 &lt;= key &lt;= 106
	At most 104 calls will be made to add, remove, and contains.


class MyHashSet:

    def __init__(self):
        self.hash_list = [0]*10000000

    def add(self, key: int) -> None:
        self.hash_list[key]+=1

    def remove(self, key: int) -> None:
        self.hash_list[key] = 0

    def contains(self, key: int) -> bool:
        if self.hash_list[key] > 0:
            return True
        return False
class MyHashSet {
	ArrayList<LinkedList<Integer>> list;
	int size = 100;

	public MyHashSet() {
		list = new ArrayList<>(size);
		for (int i = 0; i < size; i++) {
			list.add(new LinkedList<Integer>());
		}
	}

	public int hash(int key) {
		return key % list.size();
	}

	public int search(int key) {
		int i = hash(key);

		LinkedList<Integer> temp = list.get(i);
		int ans = -1;

		for (int j = 0; j < temp.size(); j++) {
			if (key == temp.get(j)) {
				return j;
			}
		}
		return ans;
	}

	public void add(int key) {
		if (search(key) == -1) {
			int i = hash(key);
			list.get(i).add(key);
		}
	}

	public void remove(int key) {
		if (search(key) != -1) {
			int i = hash(key);
			list.get(i).remove(Integer.valueOf(key));
		}
	}

	public boolean contains(int key) {
		return search(key) != -1;
	}
}
class MyHashSet {
    vector<int> v;
public:
    MyHashSet() {

    }

    void add(int key) {
        auto it = find(v.begin(), v.end(), key);
        if(it == v.end()){
            v.push_back(key);
        }

    }

    void remove(int key) {
        auto it = find(v.begin(), v.end(), key);
        if(it != v.end()){
            v.erase(it);
        }
    }

    bool contains(int key) {
        return find(v.begin(), v.end(), key) != v.end();
    }
};
var MyHashSet = function() {
  
    // Really you should just 
    // Make your own object, but instead
    // we have attached ourself to the 
    // `this` object which then becomes our hashmap.
    
    // What you should instead do is this:
    // this.hash_map = {}
    // And then update our following functions
};

MyHashSet.prototype.add = function(key) {
    
    // Constant Time
    // Linear Space | To the size of the input key
    // You can access objects using array notation

    this[key] = null;
};

MyHashSet.prototype.remove = function(key) {
    
    // Constant Time
    // Constant Space
    // You can access objects using array notation
    // Here we use the delete keyword.

    delete this[key]
};

MyHashSet.prototype.contains = function(key) {
    
    // Constant Time
    // Constant Space
    // This just asks if the property exists

    return this.hasOwnProperty(key)
};
Design HashSet