Advertisement
Guest User

Untitled

a guest
Oct 18th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.58 KB | None | 0 0
  1. def countChange(money: Int, coins: List[Int]): Int = {
  2.                 def loop(amountChange: Int, coins: List[Int]):Int = {
  3.                         if (amountChange > money) 0
  4.                         else if (amountChange == money) 1
  5.                         else {
  6.                                 loop(amountChange + coins.head, coins) +
  7.                                         (if (coins.size > 1) loop(amountChange + coins.tail.head, coins.tail)
  8.                                         else 0)
  9.                         }
  10.                 }
  11.                 loop(0,coins)
  12.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement