Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emahtab/design-hashset
https://github.com/emahtab/design-hashset
design hashset leetcode
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/emahtab/design-hashset
- Owner: eMahtab
- Created: 2022-04-09T06:57:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T04:16:04.000Z (2 months ago)
- Last Synced: 2024-10-19T06:34:55.889Z (2 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-hashsetDesign 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);
}
}
```