@@ -11,7 +11,7 @@ def sortArray(self, nums):
11
11
def mergeSort (start , end , nums ):
12
12
if end - start <= 1 :
13
13
return
14
- mid = start + (end - start ) / 2
14
+ mid = start + (end - start ) // 2
15
15
mergeSort (start , mid , nums )
16
16
mergeSort (mid , end , nums )
17
17
right = mid
@@ -37,7 +37,7 @@ def sortArray(self, nums):
37
37
:type nums: List[int]
38
38
:rtype: List[int]
39
39
"""
40
- def kthElement (nums , left , mid , right , compare ):
40
+ def kthElement (nums , left , k , right , compare ):
41
41
def PartitionAroundPivot (left , right , pivot_idx , nums , compare ):
42
42
new_pivot_idx = left
43
43
nums [pivot_idx ], nums [right ] = nums [right ], nums [pivot_idx ]
@@ -53,11 +53,11 @@ def PartitionAroundPivot(left, right, pivot_idx, nums, compare):
53
53
while left <= right :
54
54
pivot_idx = random .randint (left , right )
55
55
new_pivot_idx = PartitionAroundPivot (left , right , pivot_idx , nums , compare )
56
- if new_pivot_idx == mid - 1 :
56
+ if new_pivot_idx == k :
57
57
return
58
- elif new_pivot_idx > mid - 1 :
58
+ elif new_pivot_idx > k :
59
59
right = new_pivot_idx - 1
60
- else : # new_pivot_idx < mid - 1 .
60
+ else : # new_pivot_idx < k .
61
61
left = new_pivot_idx + 1
62
62
63
63
def quickSort (start , end , nums ):
0 commit comments