977.有序数组的平方 :https://leetcode.cn/problems/squares-of-a-sorted-array/
心得:周末再写。。。
public class Solution { public static void main(String[] args) { Solution solution = new Solution(); int[] ints = solution.sortedSquares(new int[]{-4, -1, 0, 3, 10}); for (int anInt : ints) { System.out.println(anInt); } } public int[] sortedSquares(int[] nums) { int[] result = new int[nums.length]; //旧数组的指针 int left = 0; int right = nums.length-1; //新数组从后往前进行填充 int newIndex = result.length-1; for (;left < right;){ if (nums[left] * nums[left] < nums[right] * nums[right]){ result[newIndex--] = nums[right] * nums[right]; right--; }else { result[newIndex--] = nums[left] * nums[left]; left++; } } return result; } }
209.长度最小的子数组:https://leetcode.cn/problems/minimum-size-subarray-sum/
心得:周末再补。。。
标签:977,right,nums,int,随想录,result,数组,left From: https://www.cnblogs.com/li-keke/p/16846205.html