1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58: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.6 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>给你一个按 <strong>非递减顺序</strong> 排序的整数数组 <code>nums</code>,返回 <strong>每个数字的平方</strong> 组成的新数组,要求也按 <strong>非递减顺序</strong> 排序。</p>
<ul>
</ul>
<p> </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> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code><span>1 <= nums.length <= </span>10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
<li><code>nums</code> 已按 <strong>非递减顺序</strong> 排序</li>
</ul>
<p> </p>
<p><strong>进阶:</strong></p>
<ul>
<li>请你<span style="color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">设计时间复杂度为 <code>O(n)</code> 的算法解决本问题</span></li>
</ul>