1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/排序数组(English) [sort-an-array].html

29 lines
1.1 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>Given an array of integers <code>nums</code>, sort the array in ascending order and return it.</p>
<p>You must solve the problem <strong>without using any built-in</strong> functions in <code>O(nlog(n))</code> time complexity and with the smallest space complexity possible.</p>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [5,2,3,1]
2022-03-27 20:46:41 +08:00
<strong>Output:</strong> [1,2,3,5]
2023-12-09 18:42:21 +08:00
<strong>Explanation:</strong> After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [5,1,1,2,0,0]
2022-03-27 20:46:41 +08:00
<strong>Output:</strong> [0,0,1,1,2,5]
2023-12-09 18:42:21 +08:00
<strong>Explanation:</strong> Note that the values of nums are not necessairly unique.
2022-03-27 20:46:41 +08:00
</pre>
2023-12-09 18:42:21 +08:00
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>-5 * 10<sup>4</sup> &lt;= nums[i] &lt;= 5 * 10<sup>4</sup></code></li>
</ul>