Created
August 19, 2016 16:50
-
-
Save sbsatter/e4a835140e4e9d5a623fd43bbb3cf88c to your computer and use it in GitHub Desktop.
Backtracking: GroupSum5- Coding bat Recursive 2 http://codingbat.com/prob/p138907
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 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