977.有序数组的平方
class Solution {
public int[] sortedSquares(int[] nums) {
int[] res = new int[nums.length];
int i = 0, j = nums.length - 1, k = nums.length - 1;
while (i <= j) {
int squareI = nums[i] * nums[i];
int squareJ = nums[j] * nums[j];
if (squareI <= squareJ) {
res[k] = squareJ;
j--;
} else {
res[k] = squareI;
i++;
}
k--;
}
return res;
}
}
209. 长度最小的子数组
class Solution {
public int minSubArrayLen(int target, int[] nums) {
int minLength = Integer.MAX_VALUE;
for (int start = 0; start < nums.length; start++) {
int sum = 0;
int curMinLength = 0;
for (int end = start; end < nums.length; end++) {
sum = sum + nums[end];
curMinLength++;
if (target <= sum) {
if (curMinLength < minLength) {
minLength = curMinLength;
}
break;
}
}
}
if (minLength != Integer.MAX_VALUE) {
return minLength;
} else {
return 0;
}
}
}

被折叠的 条评论
为什么被折叠?



