Created
October 16, 2021 13:22
-
-
Save Pzdrs/29428009763cf8a070674acddd290c8a to your computer and use it in GitHub Desktop.
Bill breaker
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
| public static Map<Integer, Integer> solve(int startingValue, int[] denominals) { | |
| Map<Integer, Integer> map = new LinkedHashMap<>(); | |
| int remaining = startingValue; | |
| for (int currentDenominal : denominals) { | |
| if (currentDenominal > remaining) continue; | |
| map.put(currentDenominal, remaining / currentDenominal); | |
| remaining %= currentDenominal; | |
| if (remaining == 0) break; | |
| } | |
| return map; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment