Uh oh!
There was an error while loading. Please reload this page.
forked from liuyubobobo/Play-with-Algorithm-Interview
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution1.java
More file actions
Latest commit
37 lines (30 loc) · 1015 Bytes
/
Copy pathSolution1.java
File metadata and controls
37 lines (30 loc) · 1015 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
33
34
35
36
37
// 209. Minimum Size Subarray Sum
// https://leetcode.com/problems/minimum-size-subarray-sum/description/
//
// 暴力解法
// 该方法在 Leetcode 中会超时!
// 时间复杂度: O(n^3)
// 空间复杂度: O(1)
publicclassSolution1 {
publicintminSubArrayLen(ints, int[] nums) {
if(s <= 0 || nums == null)
thrownewIllegalArgumentException("Illigal Arguments");
intres = nums.length + 1;
for(intl = 0 ; l < nums.length ; l ++)
for(intr = l ; r < nums.length ; r ++){
intsum = 0;
for(inti = l ; i <= r ; i ++)
sum += nums[i];
if(sum >= s)
res = Math.min(res, r - l + 1);
}
if(res == nums.length + 1)
return0;
returnres;
}
publicstaticvoidmain(String[] args) {
int[] nums = {2, 3, 1, 2, 4, 3};
ints = 7;
System.out.println((newSolution1()).minSubArrayLen(s, nums));
}
}