Leetcode 948 Solution

This article provides solution to leetcode question 948 (sort-an-array)

https://leetcode.com/problems/sort-an-array

Solution

class Solution:
    def sortArray(self, nums: List[int]) -> List[int]:
        def sort(nums, l, r):
            if l >= r:
                return

            target = nums[r]
            i = j = l

            while j <= r:
                if nums[j] <= nums[r]:
                    nums[i], nums[j] = nums[j], nums[i]
                    i += 1
                j += 1

            sort(nums, l, i - 2)
            sort(nums, i, r)

        sort(nums, 0, len(nums) - 1)
        return nums