Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countChange(money: Int, coins: List[Int]): Int = {
- def countAcross(money: Int, coins: List[Int], index: Int): Int = {
- if(index < coins.length)
- countVertical(money - coins(index), coins, index) +
- countAcross(money, coins, index + 1)
- else
- 0
- }
- def countVertical(money: Int, coins: List[Int], index: Int): Int = {
- if(money == 0)
- 1
- else if(money < 0)
- 0
- else
- countVertical(money - coins(index), coins, index) +
- countAcross(money, coins, index + 1)
- }
- countVertical(money, coins, 0)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement