Skip to content

Instantly share code, notes, and snippets.

@BinRoot
Created November 13, 2012 18:21
Show Gist options
  • Select an option

  • Save BinRoot/4067456 to your computer and use it in GitHub Desktop.

Select an option

Save BinRoot/4067456 to your computer and use it in GitHub Desktop.
int change(int target, int [] coins) {
if(target <= 0) {
return 0;
}
for(int i=0; i<coins.length; i++) {
if(target == coins[i]) return 1;
}
int smallest = Integer.MaxValue;
for(int i=0; i<coins.length(); i++) {
int a = change(target - coins[i], coins);
if(a < smallest) {
smallest = a;
}
}
return smallest + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment