Skip to content

Commit 5a52b0d

Browse files
committed
Runtime: 347 ms (Top 94.76%) | Memory: 22.7 MB (Top 60.86%)
1 parent 5c163b9 commit 5a52b0d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
# Runtime: 347 ms (Top 94.76%) | Memory: 22.7 MB (Top 60.86%)
12
class FreqStack:
23

34
def __init__(self):
45
self.cnt = {}
56
self.maxcount = 0
67
self.stack = {}
7-
8-
98

109
def push(self, val: int) -> None:
1110
count = self.cnt.get(val,0)+1
@@ -14,17 +13,15 @@ def push(self, val: int) -> None:
1413
self.maxcount = count
1514
self.stack[count] = []
1615
self.stack[count].append(val)
17-
16+
1817
def pop(self) -> int:
1918
res = self.stack[self.maxcount].pop()
2019
self.cnt[res]-=1
2120
if not self.stack[self.maxcount]:
2221
self.maxcount-=1
2322
return res
24-
25-
2623

2724
# Your FreqStack object will be instantiated and called as such:
2825
# obj = FreqStack()
2926
# obj.push(val)
30-
# param_2 = obj.pop()
27+
# param_2 = obj.pop()

0 commit comments

Comments
 (0)