Skip to content

Commit 1a0b3e3

Browse files
authored
Update Solution.py
1 parent 50a23fc commit 1a0b3e3

File tree

1 file changed

+9
-8
lines changed
  • solution/0200-0299/0215.Kth Largest Element in an Array

1 file changed

+9
-8
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Solution:
22
def findKthLargest(self, nums: List[int], k: int) -> int:
3-
def quick_sort(left, right, k):
4-
if left == right:
5-
return nums[left]
6-
i, j = left - 1, right + 1
7-
x = nums[(left + right) >> 1]
3+
def quick_sort(l: int, r: int) -> int:
4+
if l == r:
5+
return nums[l]
6+
i, j = l - 1, r + 1
7+
x = nums[(l + r) >> 1]
88
while i < j:
99
while 1:
1010
i += 1
@@ -17,8 +17,9 @@ def quick_sort(left, right, k):
1717
if i < j:
1818
nums[i], nums[j] = nums[j], nums[i]
1919
if j < k:
20-
return quick_sort(j + 1, right, k)
21-
return quick_sort(left, j, k)
20+
return quick_sort(j + 1, r)
21+
return quick_sort(l, j)
2222

2323
n = len(nums)
24-
return quick_sort(0, n - 1, n - k)
24+
k = n - k
25+
return quick_sort(0, n - 1)

0 commit comments

Comments
 (0)