Skip to content

Commit f161b92

Browse files
committed
Create 703.kth-largest-element-in-a-stream.py
1 parent 227962d commit f161b92

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://leetcode.cn/problems/kth-largest-element-in-a-stream/
2+
3+
4+
class KthLargest:
5+
'''
6+
Date: 2023.08.07
7+
Pass/Error/Bug: 1/0/0
8+
执行用时: 1128 ms, 在所有 Python3 提交中击败了 7.61% 的用户
9+
内存消耗:20.39 Mb, 在所有 Python3 提交中击败了 7.08% 的用户
10+
'''
11+
def __init__(self, k: int, nums: List[int]):
12+
self.k = k
13+
self.nums = sorted(nums)
14+
15+
16+
def add(self, val: int) -> int:
17+
self.nums.append(val)
18+
self.nums = sorted(self.nums)
19+
return self.nums[-self.k]
20+
21+
22+
# Your KthLargest object will be instantiated and called as such:
23+
# obj = KthLargest(k, nums)
24+
# param_1 = obj.add(val)

0 commit comments

Comments
 (0)