#977
Squares of a Sorted Array
newbie · 240 · lc easy +18 · verified · 73.6% accepted · 10,187 likes · top 84%
Description
You are given integer array nums in non-decreasing order. Square every element and return a new array of those squares, also in non-decreasing order.
Example 1:
Input: nums = [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Explanation: After squaring, the array becomes [16,1,0,9,100].
After sorting, it becomes [0,1,9,16,100].
Example 2:
Input: nums = [-7,-3,2,3,11]
Output: [4,9,9,49,121]
Code
1
2
3