912. Sort an Array

Given an array of integers nums, sort the array in ascending order.

 

Example 1:

Input: nums = [5,2,3,1]
Output: [1,2,3,5]

Example 2:

Input: nums = [5,1,1,2,0,0]
Output: [0,0,1,1,2,5]

 

Constraints:

  • 1 <= nums.length <= 50000
  • -50000 <= nums[i] <= 50000

Rust Solution

struct Solution;

impl Solution {
    fn sort_array(mut nums: Vec<i32>) -> Vec<i32> {
        nums.sort_unstable();
        nums
    }
}

#[test]
fn test() {
    let nums = vec![5, 2, 3, 1];
    let res = vec![1, 2, 3, 5];
    assert_eq!(Solution::sort_array(nums), res);
    let nums = vec![5, 1, 1, 2, 0, 0];
    let res = vec![0, 0, 1, 1, 2, 5];
    assert_eq!(Solution::sort_array(nums), res);
}

Having problems with this solution? Click here to submit an issue on github.