Created
November 13, 2012 18:21
-
-
Save BinRoot/4067456 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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