Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emahtab/design-hashset


https://github.com/emahtab/design-hashset

design hashset leetcode

Last synced: 22 days ago
JSON representation

Awesome Lists containing this project

README

        

# Design HashSet
## https://leetcode.com/problems/design-hashset

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.
```

## Implementation : Using ArrayList
```java
class MyHashSet {
List list;
public MyHashSet() {
list = new ArrayList();
}

public void add(int key) {
for(int num : list) {
if(num == key)
return;
}
list.add(key);
}

public void remove(int key) {
list.remove(new Integer(key));
}

public boolean contains(int key) {
return list.contains(key);
}
}
```