Squares of a Sorted Array有序数组的平方
Description
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.
public class Solution {
/**
* @param A: The array A.
* @return: The array of the squares.
*/
public int[] SquareArray(int[] A) {
// write your code here
if(A== null || A.length == 0){
return null ;
}
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 ;
}
}