977. squares of a sorted array

Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.

Example 1:

1
2
Input: [-4,-1,0,3,10]
Output: [0,1,9,16,100]

Example 2:

1
2
Input: [-7,-3,2,3,11]
Output: [4,9,9,49,121]
1
2
3
4
5
6
7
8
9
10
class  {
public int[] sortedSquares(int[] A) {
int[] result = new int[A.length];
for (int i = 0; i < A.length; i++) {
result[i] = A[i] * A[i];
}
Arrays.sort(result);
return result;
}
}