【头条后端笔试】大神,求指导!!!

那个第一个笔试题,求解不符合条件的颜色的个数,在本地跑没什么问题,逻辑应该也是对的,但通过率一直是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;
                }
            }
        }
    }
}

#字节跳动##Java工程师#
全部评论
你没有考虑边界吧,因为是循环的啊,还有兄弟,建议你找个代码规约学习一下,你的程序可以写的更规范一点的😄
点赞 回复 分享
发布于 2017-09-11 09:37

相关推荐

迷茫的大四🐶:看来已经准备换人了
点赞 评论 收藏
分享
DIY机器人工房:人家叫我骑驴找马
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务