-
-
Save prophile/646276 to your computer and use it in GitHub Desktop.
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 boolean hassum(int target) { | |
return hassum_recursive(-1, 0, 0, target); | |
} | |
private boolean hassum_recursive(int hi, int lo, int sum, int target) { | |
if (sum == target) { | |
return true; | |
} else if (sum > target && lo < hi) { | |
return hassum_recursive(hi, lo + 1, sum - array[lo], target); | |
} else { | |
int next = hi + 1; | |
return (next < array.length) && | |
hassum_recursive(next, lo, sum + array[next], target); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment