Problem statement

https://leetcode.com/problems/sort-an-array/

Solution

In this problem you just need to sort nums and it is not even forbidden to use libraries. So we can just use sorted(nums).

Complexity

It is O(n log n) for time and O(n) for space

Code

class Solution:
    def sortArray(self, nums):
        return sorted(nums)

Remark

There are different alternative ways how you can solve this problem, implementing some methods from scratch:

  1. Merge sort, using divide and conquer idea
  2. Quick sort, similar idea, but less memory
  3. Bucket sort if numbers are not too big.