-
Notifications
You must be signed in to change notification settings - Fork 0
/
706. Design HashMap.rb
50 lines (39 loc) · 1014 Bytes
/
706. Design HashMap.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# https://leetcode.com/problems/design-hashmap/
class MyHashMap
=begin
Initialize your data structure here.
=end
def initialize()
@data = []
end
=begin
value will always be non-negative.
:type key: Integer
:type value: Integer
:rtype: Void
=end
def put(key, value)
@data[key] = value
end
=begin
Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key
:type key: Integer
:rtype: Integer
=end
def get(key)
@data[key] || -1
end
=begin
Removes the mapping of the specified value key if this map contains a mapping for the key
:type key: Integer
:rtype: Void
=end
def remove(key)
@data[key] = nil
end
end
# Your MyHashMap object will be instantiated and called as such:
# obj = MyHashMap.new()
# obj.put(key, value)
# param_2 = obj.get(key)
# obj.remove(key)