Share my c solution


  • 2
    E
    int minSubArrayLen(int s, int* nums, int numsSize) {
        int sum=0;
        int ret=INT_MAX;
        int size=0;
        int start=0;
        int i=0;
        while(i<numsSize){
            while(i<numsSize&&sum<s){
                sum=sum+nums[i];
                i++;
                size++;
            }
            if(sum>=s){
                if(size<ret) ret=size;
            }
            while(sum>=s){
                sum=sum-nums[start];
                start++;
                size--;
                if(sum>=s){
                if(size<ret) ret=size;
                }            
            }
        }
        if(ret==INT_MAX) return 0;
        return ret;
    }

Log in to reply
 

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