Follow the template from minimum substring window. here is the solution


  • 0
    R
    public class Solution {
        public int minSubArrayLen(int s, int[] nums) {
            if (nums == null || nums.length == 0) return 0;
            int start = 0, end = 0, len = Integer.MAX_VALUE, sum = 0;
            while (end < nums.length) {
                sum += nums[end];
                while (sum >= s) {
                    len = Math.min(len, end - start + 1);
                    sum -= nums[start];
                    start++;
                }
                end++;
            }
            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.