Skip to content

Instantly share code, notes, and snippets.

@leearmee35
Created March 2, 2017 23:16
Show Gist options
  • Save leearmee35/9dce35decfa360c67790bf5c57d212ec to your computer and use it in GitHub Desktop.
Save leearmee35/9dce35decfa360c67790bf5c57d212ec to your computer and use it in GitHub Desktop.
209. Minimum Size Subarray Sum
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