Created
March 2, 2017 23:16
-
-
Save leearmee35/9dce35decfa360c67790bf5c57d212ec to your computer and use it in GitHub Desktop.
209. Minimum Size Subarray Sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int minSubArrayLen(int s, int[] nums) { | |
if (a == null || a.length == 0) | |
return 0; | |
int i = 0, j = 0, sum = 0, min = Integer.MAX_VALUE; | |
while (j < a.length) { | |
sum += a[j++]; | |
while (sum >= s) { | |
min = Math.min(min, j - i); | |
sum -= a[i++]; | |
} | |
} | |
return min == Integer.MAX_VALUE ? 0 : min; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment