Skip to main content
Back to problems
#912
Medium Algorithms

Sort an array

Array Divide and Conquer Sorting Heap (Priority Queue) Merge Sort Bucket Sort Radix Sort Counting Sort
55.9% acceptance
Feb 25, 2026
7185
841
Given an array of integers nums, sort the array in ascending order and return it. You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.

Solution

Rust
Time O(n log n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn sort_array(mut nums: Vec<i32>) -> Vec<i32> {
    nums.sort();
    nums
  }
}