https://github.com/emahtab/design-hashset
https://github.com/emahtab/design-hashset
design hashset leetcode
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/emahtab/design-hashset
- Owner: eMahtab
- Created: 2022-04-09T06:57:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T04:16:04.000Z (about 1 year ago)
- Last Synced: 2025-02-02T03:19:28.582Z (9 months ago)
- Topics: design, hashset, leetcode
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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);
}
}
```