• 문제 링크
Design HashSet - LeetCode
Can you solve this real interview question? 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
leetcode.com
• 풀이 코드
public class MyHashSet {
private final boolean[] arr;
public MyHashSet() {
arr = new boolean[1000001];
}
public void add(int key) {
arr[key] = true;
}
public void remove(int key) {
arr[key] = false;
}
public boolean contains(int key) {
return arr[key];
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 709. To Lower Case - Java (0) | 2026.10.02 |
|---|---|
| [LeetCode] 706. Design HashMap - Java (0) | 2026.10.01 |
| [LeetCode] 704. Binary Search - Java (0) | 2026.09.29 |
| [LeetCode] 703. Kth Largest Element in a Stream - Java (0) | 2026.09.28 |
| [LeetCode] 700. Search in a Binary Search Tree - Java (0) | 2026.09.27 |
댓글