Sort an Array (Quick Sort)
Given an integer array nums, sort it in ascending order using Quick Sort and return the array. Do not use a built-in sorting function. For this problem,…
Given an integer array `nums`, sort it in ascending order using Quick Sort and return the array. Do not use a built-in sorting function. For this problem, partition each active range with its final value as the pivot. Values less than or equal to the pivot belong on its left; larger values belong on its right.
- `1 <= nums.length <= 500` - `-5 * 10^4 <= nums[i] <= 5 * 10^4` - Values may repeat.
Example 1: input nums = [5,2,3,1]; output [1,2,3,5]. Partitioning places pivots into final positions, then recursively sorts both sides.
Example 2: input nums = [5,1,1,2,0,0]; output [0,0,1,1,2,5]. Equal values join the less-than-or-equal partition and remain valid duplicates.
Category: Sorting. Topic: sorting-searching. Difficulty: Medium. Patterns: divide-and-conquer, sorting.