首页 > 解决方案 > 我对 Leetcode 问题的解决方案在调试区域产生了结果,但在提交页面中给出了编译错误

问题描述

我为 leetcode 中的问题(最小大小子数组总和)创建了一个解决方案,它在我的笔记本电脑中运行,即使在 leetcode 调试区域(产生结果),但在提交页面中出现编译错误。谁能告诉我是什么导致了这个编译错误和解决方法?

下面是我得到的编译错误:(突出显示第 10 行,即使第 10 行似乎与此错误无关)

第 10 行:错误:不兼容的类型:int 无法转换为 Integer[] [在Driver .java 中]

class Solution {
    static int size=0;
    static int wsize=0;
    static int indic =0;
    public static int minSubArrayLen(Integer[] arr, int res){
        int st=0;
    for(int j=0;j<arr.length;j++){
            int a=arr[j];
            if(a==6){
    (Line no:10)    size=1;
            indic =1;
            return size;
            }
            st=st+arr[j];
            if(st==res){
                wsize=j+1;
                break;
            }
            if(st>6){
                wsize= j;
                break;
            }

        } return wsize;
    }

    public static int compare(int wsize, Integer[] arr,int res){
        int ans=0;
        for(int i =1;i<arr.length;i++){
            if(arr[i]==res){
                size=1;
                return size;
            }
            wsize= (wsize-1)+i;
            for(int k=i;k<wsize-1;k++){
                ans=ans+arr[k];
                if(ans>res){
                    break;
                }
                if(res==6){
                    size=(k+1)-i;
                }
            }

        }
        return size;
    }

    public static void main(String[] args) {
        //Integer[] arr = {1,5,7,9,-2,6,3,9};
        Integer[] arr = {1,5,7,9,-2,3,9};
        int res=6;
        size=minSubArrayLen(arr, res);
        if(size!=0 && indic==0){
            size=compare(size,arr,res);
        }
        System.out.println(size);


    }

}

标签: javaalgorithm

解决方案


推荐阅读