Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.
For example, given the array [2,3,1,2,4,3] and s = 7,
the subarray [4,3] has the minimal length under the problem constraint.
#include
#include
#include
using namespace std;
class Solution {
public:
int minSubArrayLen(int s, vector& nums) {
assert(s>0);
//[i...j]
int i=0,j=-1;
int sum=0;
int res=nums.size()+1;
while(i=s){
res=min(res,j-i+1);
}
}
if(res==nums.size()+1){
return 0;
}
return res;
}
};
int main(){
int arr[]={2,3,1,2,4,3};
vector val(arr,arr+sizeof(arr)/sizeof(int));
int s=7;
int ret=Solution().minSubArrayLen(s,val);
cout<