706. Design HashMap

https://leetcode.com/problems/design-hashmap/description/

solution

class MyHashMap:
    def __init__(self):
        self.size = 1000001
        self.data = [-1] * self.size

    def put(self, key: int, value: int) -> None:
        if 0 <= key < self.size:
            self.data[key] = value

    def get(self, key: int) -> int:
        if 0 <= key < self.size:
            return self.data[key]
        else:
            return -1

    def remove(self, key: int) -> None:
        if 0 <= key < self.size:
            self.data[key] = -1

时间复杂度:O() 空间复杂度:O()

follow up

reshard的方法

Last updated