977. 有序数组的平方
双指针法
执行用时:3 ms, 在所有 Java 提交中击败了22.44% 的用户 内存消耗:39.9 MB, 在所有 Java 提交中击败了90.37% 的用户
class Solution {public int[] sortedSquares(int[] nums) {int l = 0, r = nums.length - 1;int[] res = new int[nums.length];for (int i = nums.length - 1; i >= 0; i--) {if (Math.abs(nums[l]) < Math.abs(nums[r])) {res[i] = nums[r] * nums[r];r --;} else {res[i] = nums[l] * nums[l];l ++;}}return res;}}
