1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| var sortedSquares = function(nums) { let left =0; let right = nums.length - 1; let res = new Array(nums.length); let point = right while(left <= right){ if(nums[left]**2 > nums[right]**2){ res[point] = nums[left]**2; left++; } else{ res[point] = nums[right]**2; right--; } point-- } return res };
|