Created
August 19, 2016 16:16
-
-
Save sbsatter/4178264f9d9ec477014dc93e995aa48a to your computer and use it in GitHub Desktop.
Classic backtracking problem: Recursion-2 > groupSum prev | next | chance Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target? This is a classic backtracking recursion problem. Once you understand the recursive backtracking strategy in this problem, you can use the same patte…
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 groupSum(int start, int[] nums, int target) { | |
if(target==0){ | |
return true; | |
} | |
if(start>=nums.length){ | |
return false; | |
} | |
if(groupSum(start+1, nums, target-nums[start])){ | |
return true; | |
}else{ | |
return groupSum(start+1, nums, target); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment