Description
Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
Examples
Input:
nums = [-4,-1,0,3,10]Output:
[0,1,9,16,100]Explanation:
Squares sorted.
Input:
nums = [1]Output:
[1]Explanation:
Squaring the single element 1 gives [1]. Already sorted.
Input:
nums = [-7,-3,-1]Output:
[1,9,49]Explanation:
All negative numbers case. When squared: (-7)²=49, (-3)²=9, (-1)²=1. Sorted in ascending order: [1,9,49].
Constraints
- •
1 ≤ nums.length ≤ 10⁴