LintCode:整数排序

来源:互联网 发布:王阳明 知乎 编辑:程序博客网 时间:2024/05/16 19:29

LintCode:整数排序

class Solution:    # @param {int[]} A an integer array    # @return nothing    def sortIntegers2(self, A):        # Write your code here        i = 0        j = len(A) - 1        self.quick_sort(A, i, j)    def quick_sort(self, A, low, high):        if low < high:            i = low            j = high            tmp = A[low]            while i < j:                while i < j and A[j] >= tmp:                    j -= 1                A[i] = A[j]                while i < j and A[i] < tmp:                    i += 1                A[j] = A[i]            A[i] = tmp            self.quick_sort(A, low, i-1)            self.quick_sort(A, i+1, high)
0 0
原创粉丝点击