shopee笔试第一题


package Interview2020.Shoppee._1;

import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        //1. 获取输入
        Scanner sc = new Scanner(System.in);
        int headCount = sc.nextInt();
        int[][] map = new int[headCount][61];
        for(int i=0; i < headCount; i++){
            int scoreCount = sc.nextInt();
            for(int j=0; j < scoreCount; j++){
                int score = sc.nextInt();
                map[i][score] = 1;
            }
        }
        int matchCount = sc.nextInt();
        int[] match = new int[matchCount];
        for(int i=0; i < matchCount; i++){
            match[i] = sc.nextInt();
        }

        //2. 处理数据
        int[] scores = new int[headCount];
        for(int i=0; i < headCount; i++){
            int counter = 0;
            for(int j=0; j < matchCount; j++){
                if(map[i][match[j]] == 1)
                    counter++;
            }
            scores[i] = counter;
        }

        //3. 打印结果
        int result = 0;
        for(int i=1; i < headCount; i++){
            if(scores[i] > scores[result])
                result = i;
        }
        System.out.println(result+1);
    }
}

将结果存储在1~60map中,最后通过率67%,说是存在数组越界?
#Shopee##笔试题目##Java##春招#
全部评论
听说可能要用long型二进制bitmap来减少内存使用
点赞 回复
分享
发布于 2019-08-10 21:04

相关推荐

1 4 评论
分享
牛客网
牛客企业服务