|
| 1 | +<h2><a href="https://leetcode.com/problems/squares-of-a-sorted-array/">977. Squares of a Sorted Array</a></h2><h3>Easy</h3><hr><div><p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order, return <em>an array of <strong>the squares of each number</strong> sorted in non-decreasing order</em>.</p> |
| 2 | + |
| 3 | +<p> </p> |
| 4 | +<p><strong>Example 1:</strong></p> |
| 5 | + |
| 6 | +<pre><strong>Input:</strong> nums = [-4,-1,0,3,10] |
| 7 | +<strong>Output:</strong> [0,1,9,16,100] |
| 8 | +<strong>Explanation:</strong> After squaring, the array becomes [16,1,0,9,100]. |
| 9 | +After sorting, it becomes [0,1,9,16,100]. |
| 10 | +</pre> |
| 11 | + |
| 12 | +<p><strong>Example 2:</strong></p> |
| 13 | + |
| 14 | +<pre><strong>Input:</strong> nums = [-7,-3,2,3,11] |
| 15 | +<strong>Output:</strong> [4,9,9,49,121] |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p> </p> |
| 19 | +<p><strong>Constraints:</strong></p> |
| 20 | + |
| 21 | +<ul> |
| 22 | + <li><code><span>1 <= nums.length <= </span>10<sup>4</sup></code></li> |
| 23 | + <li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li> |
| 24 | + <li><code>nums</code> is sorted in <strong>non-decreasing</strong> order.</li> |
| 25 | +</ul> |
| 26 | + |
| 27 | +<p> </p> |
| 28 | +<strong>Follow up:</strong> Squaring each element and sorting the new array is very trivial, could you find an <code>O(n)</code> solution using a different approach?</div> |
0 commit comments