我写了一个小程序,但是发现了几个错误。我很困惑,不知道为什么以及如何解决它。谁能帮我解释这些错误并弄清楚如何使其工作?
以下是代码:
<小时/>
class Solution {
public int tribonacci(int n) {
SearchQueue searchQueue = new SearchQueue();
return searchQueue.count(n);
}
}
class SearchQueue {
private int theQueue = new int[38];
theQueue[0] = 0;
theQueue[1] = 1;
theQueue[2] = 1;
public int[] count(int n) {
if (n == 0) {
return 0;
}
if (theQueue[n] != null) {
return theQueue[n];
}
for (int i = 0; i < 38; i++) {
theQueue[n] = count(n - 3) + count(n - 2) + count(n - 1);
}
return theQueue[n];
}
}
最佳答案
这不是定义数组的正确方法。
应该是
private int[] thequeue = new int[38];
此外,在您的函数中,您应该返回 int 而不是 int[]。
关于java - 遇到语法错误怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61243341/