9月3日百度笔试第二题,用数组hash,怎么就过不了,求指教

// 本题为考试单行多行输入输出规范示例,无需提交,不计分。
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.nextLine();
        while (in.hasNextInt()) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例
            int n = in.nextInt();
            int m = in.nextInt();
            int s = m;
            in.nextLine();
            int[] hash = new int[n+1];
            while (m>0){
                int tempCount = in.nextInt();
                in.nextLine();
                while (tempCount>0){
                    int start = in.nextInt();
                    int end = in.nextInt();
                    in.nextLine();
                    for (int i=start; i<=end; i++){
                        hash[i]++;
                    }
                    tempCount--;
                }
                m--;
            }
            int resultCount = 0;
            ArrayList<Integer> list = new ArrayList<>();
            for(int i=0;i<hash.length;i++){
                if(hash[i]==s){
                    resultCount++;
                    list.add(i);
                }
            }
            System.out.println(resultCount);
            for(int i=0;i<list.size()-1;i++){
                System.out.print(list.get(i)+" ");
            }
            System.out.println(list.get(list.size()-1));
        }
    }
}
难道是没用long吗,不应该啊,题目中给范围了啊,都是在int范围内的啊

#笔试题目##百度#
全部评论
难道是超时了吗
点赞 回复 分享
发布于 2020-09-03 21:25
着急代码改的有些简陋
点赞 回复 分享
发布于 2020-09-03 21:24
我这个提示数组越界了
点赞 回复 分享
发布于 2020-09-03 21:22

相关推荐

07-11 11:15
中南大学 Java
好可爱的hr姐姐哈哈哈哈
黑皮白袜臭脚体育生:兄弟们貂蝉在一起,吕布开了
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
门口唉提是地铁杀:之前b站被一个游戏demo深深的吸引了。看up主页发现是个初创公司,而且还在招人,也是一天60。二面的时候要我做一个登录验证和传输文件两个微服务,做完要我推到github仓库,还要我加上jaeger和一堆运维工具做性能测试并且面试的时候投屏演示。我傻乎乎的做完以后人家跟我说一句现在暂时不招人,1分钱没拿到全是白干
你的秋招第一场笔试是哪家
点赞 评论 收藏
分享
07-11 13:16
湖南工学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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