my java solution


  • 0
    F
        public int minSubArrayLen(int s, int[] nums) {
            int i = 0, j = 0, sum = 0, n = nums.length, result = n + 1;
            while (j < n) {
                while (j < n && sum < s) sum += nums[j++];
                if (j == n && sum < s) break;
                while (sum >= s) {
                    result = Math.min(result, j - i);
                    sum -= nums[i++];
                }
            }
            return result > n ? 0 : result;
        }

Log in to reply
 

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