912. Sort an Array Medium

@problem@discussion
#Array#Divide and Conquer#Sorting#Heap (Priority Queue)#Merge Sort#Bucket Sort#Radix Sort#Counting Sort



1/**
2 * [912] Sort an Array
3 *
4 * Given an array of integers nums, sort the array in ascending order and return it.
5 * You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.
6 *  
7 * <strong class="example">Example 1:
8 * 
9 * Input: nums = [5,2,3,1]
10 * Output: [1,2,3,5]
11 * Explanation: After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).
12 * 
13 * <strong class="example">Example 2:
14 * 
15 * Input: nums = [5,1,1,2,0,0]
16 * Output: [0,0,1,1,2,5]
17 * Explanation: Note that the values of nums are not necessairly unique.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= nums.length <= 5 * 10^4
23 * 	-5 * 10^4 <= nums[i] <= 5 * 10^4
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/sort-an-array/
29// discuss: https://leetcode.com/problems/sort-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn sort_array(nums: Vec<i32>) -> Vec<i32> {
35        vec![]
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_912() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.