1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public int minSubArrayLen(int s, int[] nums) { int n = nums.length; int[] arr = new int[n+1]; for (int i = 1; i <= n; i++) { arr[i] = arr[i - 1] + nums[i - 1]; }
for (int l = 0; l <= n; l++) { for (int i = 0; i+l < n; i++) { int j = i + l; if (arr[j+1] - arr[i] >= s){ return j - i + 1; } } } return 0; } }
|