package leetcode;

/**
 * https://leetcode.com/problems/minimum-size-subarray-sum/
 */
public class Problem209 {
    public int minSubArrayLen(int s, int[] nums) {
        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                int sum = 0;
                for (int x = j; x < j+i && x < nums.length; x++) {
                    sum += nums[x];
                }
                if (sum >= s) {
                    return i;
                }
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Problem209 prob = new Problem209();
//        System.out.println(prob.minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 3}));
//        System.out.println(prob.minSubArrayLen(3, new int[]{2, 3, 1, 2, 4, 5}));
        System.out.println(prob.minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 5}));
    }
}

@@ -169,113 +169,67 @@
     
-for (int i = 1; i %3C nums.length; i++) %7B%0A            for (int j = 0; j %3C nums.length; j++) %7B%0A     
+int min = Integer.MAX_VALUE;%0A        int left = 0;%0A
         
    i
@@ -220,27 +220,24 @@
  0;%0A        
-   
 int sum = 0;
@@ -237,24 +237,16 @@
 um = 0;%0A
-        
         
@@ -258,27 +258,24 @@
 int 
-x = j; x %3C j+i && x
+right = 0; right
  %3C n
@@ -290,23 +290,19 @@
 th; 
-x
+right
 ++) %7B%0A
-        
     
@@ -325,9 +325,13 @@
 ums%5B
-x
+right
 %5D;%0A 
@@ -345,32 +345,13 @@
     
-    %7D%0A                if
+while
  (su
@@ -380,53 +380,81 @@
     
-    return i;%0A                %7D%0A            %7D
+min = Math.min(min, right - left + 1);%0A                sum -= nums%5Bleft%5D;
 %0A   
@@ -462,18 +462,16 @@
     
-%7D%0A
         
 retu
@@ -470,359 +470,91 @@
     
-return 0
+left++
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem209 prob = new Problem209();%0A//        System.out.println(prob.minSubArrayLen(7, new int%5B%5D%7B2, 3, 1, 2, 4, 3%7D));%0A//        System.out.println(prob.minSubArrayLen(3, new int%5B%5D%7B2, 3, 1, 2, 4, 5%7D));%0A        System.out.println(prob.minSubArrayLen(7, new int%5B%5D%7B2, 3, 1, 2, 4, 5%7D))
+    %7D%0A        %7D%0A        return (min == Integer.MAX_VALUE) ? 0 : min
 ;%0A  

Solve problem 209