O(n) || Counting Sort || 99% beat (4ms)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n![Screenshot (89).png](https://assets.leetcode.com/users/images/1d2a84d9-9cb9-4792-8431-20db88905632_1705035344.6062953.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(100000)\n# Code\n```\nclass Solution {\n    public int[] sortArray(int[] nums) {\n        int[] arr = new int[100001];\n        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;\n        int x = 0;\n        for (int i : nums) {\n            x = 50000 + i;\n            arr[x]++;\n            if (min > x)\n                min = x;\n            if (max < x)\n                max = x;\n        }\n        int k = nums.length - 1, n = k + 1;\n        for (int i = max; i >= min; i--) {\n            if (arr[i] == 0)\n                continue;\n            int len = arr[i];\n            while (len-- > 0)\n                nums[k--] = i - 50000;\n        }\n        return nums;\n    }\n}\n```
['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']