<分区>
我找到了几个月前为面试准备编写的一段代码。
根据我的评论,它试图解决这个问题:
Given some dollar value in cents (e.g. 200 = 2 dollars, 1000 = 10 dollars), find all the combinations of coins that make up the dollar value. There are only pennies (1¢), nickels (5¢), dimes (10¢), and quarters (25¢) allowed.
例如,如果给出 100,则答案应为:
4 quarter(s) 0 dime(s) 0 nickel(s) 0 pennies
3 quarter(s) 1 dime(s) 0 nickel(s) 15 pennies
etc.
我相信这可以通过迭代和递归两种方式解决。我的递归解决方案有很多问题,我想知道其他人会如何解决这个问题。这个问题的困难部分是使其尽可能高效。