Skip to content

Commit 45f37f2

Browse files
committed
[Medium] Title: 209. Minimum Size Subarray Sum - LeetCode
1 parent 86ab8c4 commit 45f37f2

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int minSubArrayLen(int target, int[] nums) {
3+
int result = Integer.MAX_VALUE;
4+
int left = 0;
5+
int right = 0;
6+
int sum = 0;
7+
while(right < nums.length) {
8+
sum += nums[right++];
9+
while(sum >= target) {
10+
result = Math.min(result, right - left);
11+
sum -= nums[left++];
12+
}
13+
}
14+
return (result == Integer.MAX_VALUE) ? 0 : result;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# [Midium] 209. Minimum Size Subarray Sum
2+
3+
[문제 링크](https://leetcode.com/problems/minimum-size-subarray-sum/description/?envType=study-plan-v2&envId=top-interview-150)
4+
5+
### 문제 설명
6+
Given an array of positive integers`nums`and a positive integer`target`, return*the**minimal length**of asubarraywhose sum is greater than or equal to*`target`. If there is no such subarray, return`0`instead.
7+
8+
### 입출력
9+
Example 1:
10+
11+
```Input: target = 7, nums = [2,3,1,2,4,3]
12+
Output: 2
13+
```
14+
Explanation: The subarray [4,3] has the minimal length under the problem constraint.
15+
16+
Example 2:
17+
18+
```Input: target = 4, nums = [1,4,4]
19+
Output: 1
20+
```
21+
22+
Example 3:
23+
```
24+
Input: target = 11, nums = [1,1,1,1,1,1,1,1]
25+
Output: 0
26+
```
27+
### 문제설명
28+
Constraints:
29+
- 1 <= target <= 109
30+
- 1 <= nums.length <= 105
31+
- 1 <= nums[i] <= 104

0 commit comments

Comments
 (0)