【速速补充笔记】
977.有序数组的平方
class Solution {
public int[] sortedSquares(int[] nums) {
int left = 0, right = nums.length - 1, point = right;
int[] answer = new int[nums.length];
while (left <= right) {
if ((nums[right] * nums[right]) > (nums[left] * nums[left])) {
answer[point] = nums[right] * nums[right];
right--;
} else {
answer[point] = nums[left] * nums[left];
left++;
}
point--;
}
return answer;
}
}
209.长度最小的子数组
class Solution {
public int minSubArrayLen(int target, int[] nums) {
int end, start = 0;
int sum = 0;
int answer = nums.length + 1;
int subLength;
for (end = 0; end < nums.length; end++) {
sum += nums[end];
while (sum >= target) {
subLength = end - start + 1;
answer = Math.min(answer, subLength);
sum -= nums[start];
start++;
}
}
return answer == nums.length + 1 ? 0 : answer;
}
}
标签:妹有,速速,right,end,nums,int,代码,answer,left
From: https://www.cnblogs.com/Chain-Tian/p/16909804.html