Advertisement
Guest User

Untitled

a guest
May 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.37 KB | None | 0 0
  1. def countChange(money: Int, coins: List[Int]): Int = {
  2.     var ret = 0
  3.  
  4.     def iterator(money: Int, coins: List[Int]) {
  5.       if (!coins.isEmpty) {
  6.         val rest = money - coins.head
  7.  
  8.         if (rest > 0) iterator(rest, coins)
  9.         else if (rest == 0) ret = ret + 1
  10.  
  11.         iterator(money, coins.tail)
  12.       }
  13.     }
  14.  
  15.     iterator(money, coins)
  16.     ret
  17.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement