My java AC solution with two points


  • 1
    Y
    public class Solution {
    public int minSubArrayLen(int s, int[] nums) {
        int start=0;
        int sum=0;
        int res=0;
        for(int i=0;i<nums.length;i++){
            sum=sum+nums[i];
            if(sum>=s){
              while(sum>=s){
                sum=sum-nums[start];
                start++;
              }
              int len=i-start+2;
              if(res==0||res>len) res=len;
            }
        }
        return res;
    }
    

    }


Log in to reply
 

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