• 문제 링크
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;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 717. 1-bit and 2-bit Characters - Java (0) | 2026.10.03 |
|---|---|
| [LeetCode] 709. To Lower Case - Java (0) | 2026.10.02 |
| [LeetCode] 705. Design HashSet - Java (0) | 2026.09.30 |
| [LeetCode] 704. Binary Search - Java (0) | 2026.09.29 |
| [LeetCode] 703. Kth Largest Element in a Stream - Java (0) | 2026.09.28 |
댓글