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 (Chinese)/有序数组的平方 [squares-of-a-sorted-array].html

40 lines
1.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个按 <strong>非递减顺序</strong> 排序的整数数组 <code>nums</code>,返回 <strong>每个数字的平方</strong> 组成的新数组,要求也按 <strong>非递减顺序</strong> 排序。</p>
<ul>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [-4,-1,0,3,10]
<strong>输出:</strong>[0,1,9,16,100]
<strong>解释:</strong>平方后,数组变为 [16,1,0,9,100]
排序后,数组变为 [0,1,9,16,100]</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [-7,-3,2,3,11]
<strong>输出:</strong>[4,9,9,49,121]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code><span>1 &lt;= nums.length &lt;= </span>10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
<li><code>nums</code> 已按 <strong>非递减顺序</strong> 排序</li>
</ul>
<p>&nbsp;</p>
<p><strong>进阶:</strong></p>
<ul>
<li>请你设计时间复杂度为 <code>O(n)</code> 的算法解决本问题</li>
</ul>