import java.util.*;

/**
 * Given an array of n positive integers and a positive integer s, find the 
 * minimal length of a subarray of which the sum ≥ s. If there isn't one, return 
 * 0 instead.
 * 
 * For example, given the array [2,3,1,2,4,3] and s = 7,
 * the subarray [4,3] has the minimal length under the problem constraint.
 * 
 * More practice:
 * If you have figured out the O(n) solution, try coding another solution of 
 * which the time complexity is O(n log n).
 * 
 * Tags: Array, Two Pointers, Binary Search
 *
 * Similar Problems: (H) Minimum Window Substring, (E) Maximum Size Subarray Sum 
 *                  Equals k
 */
class MinSizeSubarraySum {
    public int minSubArrayLen(int s, int[] nums) {
        
    }
}
@@ -663,16 +663,45 @@
 raySum %7B
+%0A%0A    /**%0A     * O(n)%0A     */
 %0A    pub
@@ -752,16 +752,1113 @@
         
+if (nums == null %7C%7C nums.length == 0) return 0;%0A%0A        int start = 0;%0A        int end = 0;%0A        int sum = 0;%0A        int min = Integer.MAX_VALUE;%0A%0A        while (end %3C nums.length) %7B%0A            sum += nums%5Bend++%5D;%0A            while (sum %3E= s) %7B%0A              min = Math.min(min, end - start);%0A              sum -= nums%5Bstart++%5D;%0A            %7D%0A        %7D%0A%0A        return min == Integer.MAX_VALUE ? 0 : min;%0A    %7D%0A    %0A    /**%0A     * O(nlogn)%0A     */%0A    public int minSubArrayLen2(int s, int%5B%5D nums) %7B%0A        int i = 1;%0A        int j = nums.length;%0A        int min = 0;%0A        while (i %3C= j) %7B%0A            int mid = (j - i) / 2 + i;%0A            if (isWindowExist(mid, nums, s)) %7B%0A                j = mid - 1;%0A                min = mid;%0A            %7D else i = mid + 1;%0A        %7D%0A        return min;%0A    %7D%0A    %0A    private boolean isWindowExist(int size, int%5B%5D nums, int s) %7B%0A        int sum = 0;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (i %3E= size) sum -= nums%5Bi - size%5D;%0A            sum += nums%5Bi%5D;%0A            if (sum %3E= s) return true;%0A        %7D%0A        return false;
 %0A    %7D%0A%7D

add 2 solutions