class Solution {
public int minSubArrayLen(int target, int[] nums) {
int i = 0;
int res = Integer.MAX_VALUE;
int sum = 0;
for (int j = 0; j < nums.length; j++) {
sum += nums[j];
while (sum >= target) {
int subL = j - i + 1;
res = Math.min(res, subL);
sum -= nums[i++];
}
}
return res == Integer.MAX_VALUE ? 0 : res;
}
}
class Solution {
public int[][] generateMatrix(int n) {
int loop = 0;
int count = 1;
int start = 0;
int[][] res = new int[n][n];
int i, j;
while (loop++ < n / 2) {
//left -> right
for (j = start; j < n - loop; j++) {
res[start][j] = count++;
}
for (i = start; i < n - loop; i++) {
res[i][j] = count++;
}
for (; j >= loop; j--) {
res[i][j] = count++;
}
for (; i >= loop; i--) {
res[i][j] = count++;
}
start++;
}
if (n % 2 == 1) {
res[start][start] = count;
}
return res;
}
}