java - 遇到语法错误怎么办?

标签 java algorithm

我写了一个小程序,但是发现了几个错误。我很困惑,不知道为什么以及如何解决它。谁能帮我解释这些错误并弄清楚如何使其工作? enter image description here

以下是代码:

<小时/>

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/

相关文章:

java - 请帮助我理解 :\0 的用法

java - 简单数组的问题

algorithm - 给定一个未排序的整数数组 A,返回一个数组 B,其中 B[i] 是 A[j] 的数量,使得 A[i] > A[j] 而 i < j

algorithm - 最小化二叉树范围总和的内存消耗和执行时间

algorithm - A* 启发式创建 Bresenham 线

在列表中查找共同名称的算法

java - 如何从一个txt文件填充2个数组

java - 使用 JNotify 库,您如何判断删除的文件是文件还是目录?

java - 找不到 org.codehaus.mojo

algorithm - 通过日志处理小概率