Class Solution
java.lang.Object
g0901_1000.s0977_squares_of_a_sorted_array.Solution
977 - Squares of a Sorted Array.<p>Easy</p>
<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>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [-4,-1,0,3,10]</p>
<p><strong>Output:</strong> [0,1,9,16,100]</p>
<p><strong>Explanation:</strong> After squaring, the array becomes [16,1,0,9,100].</p>
<p>After sorting, it becomes [0,1,9,16,100].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [-7,-3,2,3,11]</p>
<p><strong>Output:</strong> [4,9,9,49,121]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
<li><code>nums</code> is sorted in <strong>non-decreasing</strong> order.</li>
</ul>
<p><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?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
sortedSquares
public int[] sortedSquares(int[] nums)
-