Share my C code


  • 0
    C

    #define min(a,b) (a)>(b)?(a):(b)
    int minSubArrayLen(int s, int* nums, int numsSize) {
    int i=0, j=0;
    if(numsSize==0){
    return 0;
    }
    int l=0, sum=0;
    int start=0, end=0;
    for(i=0; i<numsSize; i++){
    sum=sum+nums[i];
    while(sum>=s){
    if(l==0 || l>i-j+1){
    l=i-j+1;
    }
    sum=sum-nums[j++];

        }
    }
    return l;
    

    }


Log in to reply
 

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