input: Write a function to optimize the provided Python code for sorting a list of numbers in O(n) time complexity. The function should take a list of unsorted numbers as input and return a list of sorted numbers. If the input list is empty, the function should return an empty list.
  assert sort_list([2, 6, 3, 8, 4])==[2, 3, 4, 6, 8]
  assert sort_list([9, 1, 5, 2, 7])==[1, 2, 5, 7, 9]
  assert sort_list([1])==[1]
  assert sort_list([])==[]
output: def sort_list(nums):
      if not nums:
          return []
      max_num = max(nums)
      count = [0] * (max_num + 1)
      for num in nums:
          count[num] += 1
      sorted_nums = []
      for i in range(len(count)):
          sorted_nums.extend([i] * count[i])
      return sorted_nums