Skip to content

Instantly share code, notes, and snippets.

@sbsatter
Created August 19, 2016 16:50
Show Gist options
  • Save sbsatter/e4a835140e4e9d5a623fd43bbb3cf88c to your computer and use it in GitHub Desktop.
Save sbsatter/e4a835140e4e9d5a623fd43bbb3cf88c to your computer and use it in GitHub Desktop.
Backtracking: GroupSum5- Coding bat Recursive 2 http://codingbat.com/prob/p138907
public boolean groupSum5(int start, int[] nums, int target) {
if(start>=nums.length){
return target==0;
}
if(nums[start]%5 == 0 && start<nums.length-1 && nums[start+1]!=1){
return groupSum5(start+1, nums, target-nums[start]);
}else if(nums[start]%5==0){
return(groupSum5(start+2, nums, target-nums[start]));
}else if(groupSum5(start+1, nums, target-nums[start])){
return true;
}else if(groupSum5(start+1, nums, target)){
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment