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

相关推荐

不愿透露姓名的神秘牛友
06-27 20:15
点赞 评论 收藏
分享
是每个人事都这样与找工作的人这样沟通吗?正常询问不可以吗
据说名字越长别人越关注你的昵称我觉得我要被关注了:excal 我还真不会
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-27 20:55
点赞 评论 收藏
分享
评论
1
4
分享

创作者周榜

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