Can anyone help out?? Passing 12/13 cases


  • 0
    S

    class Solution {
    public:
    int minSubArrayLen(int s, vector<int>& nums)
    {
    int n=nums.size();
    int i;
    int sum=0;
    int ll,ul;
    int ans=0;

        i=0;
        while( i<n && sum<s)
        {
            sum+=nums[i];
            if(sum>=s)
              break;
            
            i++;
        }
        if(sum<s)
          return 0;
        // now we will get some finite length
        
        ll=0;
        ul=i;
        
        ans=ul-ll+1;
        
        while(ul<n)
        {
            //try increasing ll
            
            while( ll<ul && sum-nums[ll]>=s)
            {
                ll++;
                sum=sum-nums[ll];
            }
            if(ul-ll+1<ans)
              ans=ul-ll+1;
            
            ul++;
            if(ul<n)
              sum+=nums[ul];
        }
        return ans;
        
    }
    

    };enter code here


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.