去哪儿第一题

去哪儿第一题
输入:
1 2 3 4 5 5 5 5 5
输出:长度超过一半的数字
直接nextLine 空格split内存超,下面代码时间超,最终只有88%。
奇怪的是Integer.parseInt(sc.next()) 88%
int tmp = sc.nextInt();只有 75%

!sc.hasNext("\r\n"); 解析不到回车结束,hashNext贴上去就能过。
不会写代码了,已提交。
public class Main { public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);  int num = sc.nextInt();  int times = 1;  while(sc.hasNext()){  int tmp = Integer.parseInt(sc.next());  if(tmp == num){
                times++;  }else{
                times--;  }  if(times == 0){
                num = tmp;  times = 1;  }
        }
        System.out.println(num);  }
}


#笔试题目##去哪儿#
全部评论
请问去哪儿笔试要开摄像头吗
点赞 回复 分享
发布于 2018-09-28 19:33
63
点赞 回复 分享
发布于 2018-09-28 19:01
我才0.5
点赞 回复 分享
发布于 2018-09-27 17:33
我也是63
点赞 回复 分享
发布于 2018-09-27 11:08
我的类似,只有63%,用hashmap也是只有63,我估计他的输入可能中间有多个空格存在
点赞 回复 分享
发布于 2018-09-27 11:08
一样的思路,也只有88%,说超时
点赞 回复 分享
发布于 2018-09-27 10:45

相关推荐

04-06 16:59
已编辑
河南工业大学 Java
牛牛牛的牛子:最好扔了,实在没有选择的选择
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务