1ms Java Solution


  • 0
    J
    public class Solution {
        public int minSubArrayLen(int s, int[] nums) {
            
            
            int tempSum=0,start=0,len=Integer.MAX_VALUE;
            
            for(int i=0;i<nums.length;i++)
            {
                tempSum+=nums[i];
               
                while(tempSum>=s)
                {
                    len= Math.min(len,(i-start+1));
                    tempSum-=nums[start++];
                }
            }
            
            return len==Integer.MAX_VALUE ? 0 : len;
            
        }
    }
    

Log in to reply
 

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