input: Write a function to optimize the given Python code that sorts a set of numbers in O(n) time complexity. 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([5, 2, 9, 1, 5])==[1, 2, 5, 5, 9]
  assert sort_list([3, 3, 3, 3, 3])==[3, 3, 3, 3, 3]
  assert sort_list([])==[]
output: def sort_list(nums):
      if not nums:
          return []
      max_val = max(nums)
      count = [0] * (max_val + 1)
      for num in nums:
          count[num] += 1
      sorted_list = []
      for i in range(max_val + 1):
          sorted_list.extend([i] * count[i])
      return sorted_list