Skip to content

Commit 82ca8c9

Browse files
authored
Update Kth Largest Element in an Array - Leetcode 215.py
1 parent 49c8750 commit 82ca8c9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Kth Largest Element in an Array - Leetcode 215/Kth Largest Element in an Array - Leetcode 215.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Brute Force Solution
2+
import heapq
3+
class Solution:
4+
def findKthLargest(self, nums: List[int], k: int) -> int:
5+
nums.sort()
6+
return nums[-k]
7+
8+
# Time: O(n log n)
9+
# Space: O(1)
10+
111
import heapq
212
class Solution:
313
def findKthLargest(self, nums: List[int], k: int) -> int:
@@ -10,7 +20,7 @@ def findKthLargest(self, nums: List[int], k: int) -> int:
1020
heapq.heappop(nums)
1121

1222
return -heapq.heappop(nums)
13-
# Max Heap of size n
23+
# Max Heap of size n
1424
# Time: O(n + k log n)
1525
# Space: O(1)
1626

0 commit comments

Comments
 (0)