public static int[] sortedSquares(int[] nums) {
int len = nums.length;
int[] result = new int[len];
for(int i = 0,j = len - 1,pos = len -1;i <=j;){
if(nums[i] * nums[i] > nums[j] * nums[j]){
result[pos--] = nums[i] * nums[i];
i++;
}else{
result[pos--] = nums[j] * nums[j];
j--;
}
}
return result;
}
03-23
860
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-14
94
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-02
190
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)