面试常见算法题---快速排序python

利用递归进行快速排序

class Solution():
    def quicksort(self, list, low, high):
        if low >= high:
            return list
        left = low
        right = high
        num = list[low]
        while left < right:
            while list[right] >= num and left < right:
                right = right - 1
            list[left] = list[right]
            while list[left] <= num and left < right:
                left = left + 1
            list[right] = list[left]
        list[left] = num
        return self.quicksort(list, low, left-1)
        return self.quicksort(list, left+1, high)

你可能感兴趣的:(面试常见算法题---快速排序python)