标签:ima mic ide inf turn img view subarray minimum
要求
示例
思路
1 class Solution{ 2 public: 3 int minSubArrayLen(int s, vector<int>& nums){ 4 int l = 0, r = -1; 5 int sum = 0; 6 int res = nums.size() + 1; 7 8 while( l < nums.size()) { 9 if( r+1 < nums.size() && sum < s) 10 sum += nums[++r]; 11 else 12 sum -= nums[l++]; 13 if(sum >= s) 14 res = min(res,r-l+1); 15 } 16 if(res== nums.size()+1) 17 return 0; 18 return res; 19 } 20 };
延伸
[刷题] LeetCode 209 Minimum Size Subarray Sum
标签:ima mic ide inf turn img view subarray minimum
原文地址:https://www.cnblogs.com/cxc1357/p/12585766.html