Notice
250x250
Recent Posts
Recent Comments
Link
넘치게 채우기
[LeetCode] 705. Design HashSet 본문
728x90
반응형
https://leetcode.com/problems/design-hashset/description/
문제 유형 : 해시
문제 난이도 : Easy
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.
라이브러리 없이 간단한 해시 집합을 구현하라.
풀이
배열을 하나 만들어서 구현해주면 된다
코드(C++)
class MyHashSet {
public:
vector<int> set;
MyHashSet() {
}
void add(int key) {
set.push_back(key);
}
void remove(int key) {
set.erase(std::remove(set.begin(), set.end(), key), set.end());
}
bool contains(int key) {
return count(set.begin(), set.end(), key) > 0;
}
};
728x90
반응형
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] 547. Number of Provinces (0) | 2023.06.04 |
---|---|
[LeetCode] 64. Minimum Path Sum (0) | 2023.05.30 |
[LeetCode] 53. Maximum Subarray (0) | 2023.05.29 |
[LeetCode] 2542. Maximum Subsequence Score (0) | 2023.05.24 |
[LeetCode] 703. Kth Largest Element in a Stream (0) | 2023.05.23 |