Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countChange(money: Int, coins: List[Int]): Int = {
- var ret = 0
- def iterator(money: Int, coins: List[Int]) {
- if (!coins.isEmpty) {
- val rest = money - coins.head
- if (rest > 0) iterator(rest, coins)
- else if (rest == 0) ret = ret + 1
- iterator(money, coins.tail)
- }
- }
- iterator(money, coins)
- ret
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement