My C# AC using Two pointer solution


  • 0
    public class Solution {
        public int MinSubArrayLen(int s, int[] nums) {
            int min = Int32.MaxValue;
            if(nums.Count()==0) return 0;
            int sum =nums[0];
            int j =1;
            int i =0;
            while(j< nums.Count() && i< nums.Count())
            {
                while(sum<s && j< nums.Count()) sum += nums[j++];
                
                while(sum>=s && i<j) sum = sum- nums[i++];
    
                min = Math.Min(min,j +1 - i);
            }
            if(i ==0) return 0;
            return min;
        }
    }

Log in to reply
 

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