912. Sort an Array

Quick Sort

class Solution:  
    def divide(self, nums: List[int], l: int, r: int) -> int:
        target = nums[l]

        while l < r:
            while l < r and target <= nums[r]:
                r -= 1

            nums[l] = nums[r]

            while l < r and nums[l] <= target:
                l += 1

            nums[r] = nums[l]

        m = l
        nums[m] = target

        return m

    def quickSort(self, nums: List[int], l: int, r: int):
        if l < r:
            m = self.divide(nums, l, r)
            self.quickSort(nums, l, m-1)
            self.quickSort(nums, m+1, r)

    def sortArray(self, nums: List[int]) -> List[int]:
        l, r = 0, len(nums)-1
        self.quickSort(nums, l, r)
        return nums