maxNumRepeated([],4) --> 0
maxNumRepeated([1],4) --> 0
maxNumRepeated([1,4,3],4) --> 1
maxNumRepeated([1,4,3,4,4,3],4) --> 2
maxNumRepeated([1,4,4,4,3],4) --> 3
maxNumRepeated([1,4,3,4,3,4],4) --> 1
public static int maxNumRepeated(Integer[] a, Integer elem) {
int cont = 1;
int cont2 = 0;
int maxNum = 0;
if(a.length==1&&a[0].equals(elem)){
maxNum = 1;
}else if(a.length==0){
maxNum = 0;
}else {
for(int i = 0;i<a.length-1;i++){
if(a[i].equals(elem)){
if(a[i].equals(a[i+1])){
cont++;
}
maxNum = cont;
}
}
}
return maxNum;
}
java菜鸟求助啊maxNumRepeated ([1,1,3,3,3,3,2,3,3,3],3)返回的是 6 怎么改才能 返回4呢
忽略 count2 忘了去掉了
慕娘9325324
蝴蝶不菲
相关分类