Leetcode 948 Solution
This article provides solution to leetcode question 948 (sort-an-array)
Access this page by simply typing in "lcs 948" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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