Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2010 03:37
Show Gist options
  • Save anonymous/646264 to your computer and use it in GitHub Desktop.
Save anonymous/646264 to your computer and use it in GitHub Desktop.
public boolean hassum(int target) {
if (array.length == 0)
{
return false;
}
int hi = 0;
int lo = 0;
int sum = array[0];
while ((hi < array.length) && (lo < array.length))
{
if (sum == target)
{
return true;
}
if (sum > target)
{
sum -= array[lo];
lo++;
}
if (sum < target)
{
hi++;
sum += array[hi];
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment