【发布时间】:2014-01-04 15:48:20
【问题描述】:
我正在尝试实现一个程序,该程序计算从硬币列表中获取特定数量的可能性的数量,但我得到了错误
在 coin(s-1) 的这一行中,对于 Money 类型的方法 coin(int) 未定义:
返回梳子(s-1,数量,硬币)+梳子(s,数量-硬币(s-1),硬币);
这是我的代码
class List<T> {
T head;
List<T> tail;
List(T head, List<T> tail) {
this.head = head;
this.tail = tail;
}
static <U> List<U> node(U head, List<U> tail) {
return new List<U>(head, tail);
}
}
public class Money{
//should count number of combinations to get change amount amount
static int comb(int s, int amount, List<Integer> coins) {
if (amount == 0 )
return 1;
else if (amount < 0)
return 0;
return comb(s-1, amount, coins) + comb(s, amount-coins(s-1), coins);
有什么问题?
【问题讨论】:
-
你为什么使用你自己的
List类? 确切地 将其命名为 Java'sListinterface 会让人感到困惑,而且它似乎比普通的ArrayList或LinkedList没有任何优势。