본문 바로가기
Problem Solving/LeetCode

[LeetCode] 706. Design HashMap - Java

by graycode 2026. 10. 1.

• 문제 링크

 

Design HashMap - LeetCode

Can you solve this real interview question? Design HashMap - Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: * MyHashMap() initializes the object with an empty map. * void put(int key, int value) inserts a (

leetcode.com

 

• 풀이 코드

import java.util.Arrays;

public class MyHashMap {

    private final int[] arr;

    public MyHashMap() {
        arr = new int[1000001];
        Arrays.fill(arr, -1);
    }

    public void put(int key, int value) {
        arr[key] = value;
    }

    public int get(int key) {
        return arr[key];
    }

    public void remove(int key) {
        arr[key] = -1;
    }

}

댓글