【头条后端笔试】大神,求指导!!!
那个第一个笔试题,求解不符合条件的颜色的个数,在本地跑没什么问题,逻辑应该也是对的,但通过率一直是0,好歹给的例子能过,能有10%吧???
请帮忙看下代码有什么问题
package com.sy;
import java.util.*;
public class Test7 {
private static List<int[]> nodeList = new ArrayList<>();
private static int m;
private static boolean[] error_color;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
m = scanner.nextInt();
int c = scanner.nextInt();
error_color = new boolean[c+1];
int tmp;
for (int i = 1; i <= n; ++i){
tmp = scanner.nextInt();
int[] tmp_array = new int[tmp];
for (int j = 0; j < tmp; ++j)
tmp_array[j] = scanner.nextInt();
nodeList.add(tmp_array);
}
for (int i = 0; i < m-1; ++i)
nodeList.add(nodeList.get(i));
deal();
int error_num = 0;
for (boolean b : error_color)
if (b)
++error_num;
System.out.println(error_num);
scanner.close();
}
public static void deal(){
int tmp2;
for (int i = 0; i <= nodeList.size() - m; ++i){
Set<Integer> set = new HashSet<>();
tmp2 = 0;
for (int j = i; j < i + m; ++j){
for (int n : nodeList.get(j)) {
set.add(n);
tmp2++;
if (set.size() < tmp2)
error_color[n] = true;
}
}
}
}
}
查看17道真题和解析
