双指针解法
class Solution { public int[] sortedSquares(int[] nums) { int[] result = new int[nums.length]; int right = nums.length - 1; int index = nums.length - 1; int left = 0; while(left <= right){ if(nums[right] * nums[right] >= nums[left] * nums[left]){ result[index--] = nums[right] * nums[right]; right--; }else{ result[index--] = nums[left] * nums[left]; left++; } } return result; } }