본문 바로가기
Problem Solving/LeetCode

[LeetCode] 705. Design HashSet - Java

by graycode 2026. 9. 30.

• 문제 링크

 

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];
    }

}

댓글