LeetCode 풀이노트
[C#] 705. Design HashSet
iOEEO
2023. 5. 30. 18:16
반응형
1. 문제
내장된 해시테이블 라이브러리를 사용하지 않고 HastSet class를 구현하면 된다.
2. 풀이 과정
0 <= key <= 1000000 이므로 1000001개의 bool 배열을 만든 뒤 key를 index로 사용한다.
public class MyHashSet {
bool[] arr;
public MyHashSet() {
arr = new bool[1000000 + 1];
}
public void Add(int key) {
arr[key] = true;
}
public void Remove(int key) {
arr[key] = false;
}
public bool Contains(int key) {
return arr[key];
}
}
반응형