-
Notifications
You must be signed in to change notification settings - Fork 12
/
solution.py
32 lines (28 loc) · 882 Bytes
/
solution.py
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
class AllOne:
def __init__(self):
self.myDict = {}
def inc(self, key: str) -> None:
if key in self.myDict:
self.myDict[key] += 1
else:
self.myDict[key] = 1
def dec(self, key: str) -> None:
if key in self.myDict:
if self.myDict[key] > 1:
self.myDict[key] -= 1
else:
self.myDict.pop(key)
def getMaxKey(self) -> str:
if not self.myDict:
return ""
maxVal = max(self.myDict.values())
for key in self.myDict.keys():
if self.myDict[key] == maxVal:
return key
def getMinKey(self) -> str:
if not self.myDict:
return ""
minVal = min(self.myDict.values())
for key in self.myDict.keys():
if self.myDict[key] == minVal:
return key