209.长度最小的子数组
class Solution {
public int minSubArrayLen(int target, int[] nums) {
int fastIndex = 0;
int slowIndex = 0;
int sums = 0;
int result = Integer.MAX_VALUE;
for (fastIndex = 0; fastIndex < nums.length; fastIndex++) {
sums += nums[fastIndex];
while (sums >= target) { //直到小于或等于
if ((fastIndex - slowIndex + 1) <= result) {
result = (fastIndex - slowIndex + 1);
}
sums -= nums[slowIndex];
slowIndex ++;
}
}
return result == Integer.MAX_VALUE ? 0 : result;
}
}
59.螺旋矩阵II
class Solution {
public int[][] generateMatrix(int n) {
int x = 0; int y = 0;
int[][] result = new int[n][n];
int count = 1;
for (int i = 0; i < n/2 + n % 2 ; i++ ) {
//一轮一轮的填
int sLength = n - 1 -2 * i;//填的长度
for(int j = 0; j < sLength; j++) result[x][y++] = count++ ;
for(int j = 0; j < sLength; j++) result[x++][y] = count++;
for(int j = 0; j < sLength; j++) result[x][y--] = count++;
for(int j = 0; j < sLength; j++) result[x--][y] = count++;
x++;y++;
}
if (n % 2 ==1){
result[n / 2][n / 2] = count;
}
return result;
}
}
标签:count,59,209,sLength,Day2,++,fastIndex,int,result
From: https://blog.csdn.net/m0_51395560/article/details/142214968