Skip to content

Commit 95f1e53

Browse files
authoredAug 24, 2019
Update sort-an-array.py
1 parent 5e7314c commit 95f1e53

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎Python/sort-an-array.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def sortArray(self, nums):
1111
def mergeSort(start, end, nums):
1212
if end - start <= 1:
1313
return
14-
mid = start + (end - start) / 2
14+
mid = start + (end - start) // 2
1515
mergeSort(start, mid, nums)
1616
mergeSort(mid, end, nums)
1717
right = mid
@@ -37,7 +37,7 @@ def sortArray(self, nums):
3737
:type nums: List[int]
3838
:rtype: List[int]
3939
"""
40-
def kthElement(nums, left, mid, right, compare):
40+
def kthElement(nums, left, k, right, compare):
4141
def PartitionAroundPivot(left, right, pivot_idx, nums, compare):
4242
new_pivot_idx = left
4343
nums[pivot_idx], nums[right] = nums[right], nums[pivot_idx]
@@ -53,11 +53,11 @@ def PartitionAroundPivot(left, right, pivot_idx, nums, compare):
5353
while left <= right:
5454
pivot_idx = random.randint(left, right)
5555
new_pivot_idx = PartitionAroundPivot(left, right, pivot_idx, nums, compare)
56-
if new_pivot_idx == mid - 1:
56+
if new_pivot_idx == k:
5757
return
58-
elif new_pivot_idx > mid - 1:
58+
elif new_pivot_idx > k:
5959
right = new_pivot_idx - 1
60-
else: # new_pivot_idx < mid - 1.
60+
else: # new_pivot_idx < k.
6161
left = new_pivot_idx + 1
6262

6363
def quickSort(start, end, nums):

0 commit comments

Comments
 (0)
Please sign in to comment.