C# O(n) two pointer like the solution Minimum Window Substring


  • 0
    Y
    public class Solution {
        public int MinSubArrayLen(int s, int[] nums) {
            int n=nums.Length;
            int start=0,end=0,sum=s,min=int.MaxValue;
            while(end<n)
            {
                sum -= nums[end];
                while(sum<=0)
                {
                    min=Math.Min(end-start+1,min);
                    sum+=nums[start];
                    start++;
                }
                end++;
            }
            if(min==int.MaxValue)
                return 0;
            return  min;
        }
    }

Log in to reply
 

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