-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumSizeSubarraySum.java
More file actions
32 lines (27 loc) · 617 Bytes
/
Copy pathMinimumSizeSubarraySum.java
File metadata and controls
32 lines (27 loc) · 617 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Array;
public class MinimumSizeSubarraySum {
public static int minSubArrayLen(int s, int[] nums) {
int count[] = new int[nums.length+1];
int min = Integer.MAX_VALUE;
count[0] = 0;
for (int i = 1; i < count.length; i++) {
count[i] = count[i-1]+nums[i-1];
for (int j = i-1; j >=0 ; j--) {
if (count[i] - count[j] >= s) {
if (i-j<min) {
min = i-j;
}
break;
}
}
}
if (min == Integer.MAX_VALUE) {
min = 0;
}
return min;
}
public static void main(String[] args) {
int[] nums = {2,3,1,2,4,3};
System.out.println(minSubArrayLen(7, nums));
}
}