209 LeetCode Java : Minimum Size Subarray Sum – Medium
Problem:
Thoughts:
Solutions:
public class Solution {
public int minSubArrayLen(int s, int[] nums) {
if (nums.length == 0)
return 0;
int min = Integer.MAX_VALUE;
int left = 0;
int right = 0;
int sum = nums[left];
while (right < nums.length){
if (sum >= s){
if (right - left + 1 < min)
min = right - left + 1;
sum = sum - nums[left];
left ++;
}
else{
if (right == nums.length - 1)
break;
else{
right ++;
sum = sum + nums[right];
}
}
}//while
if (min == Integer.MAX_VALUE)
return 0;
else
return min;
}
}Previous208 LeetCode Java: Implement Trie (Prefix Tree) – MediumNext210 LeetCode Java: Course Schedule II – Medium
Last updated