蔚来8.28笔试java

java后端编程前两题AC,第一题leetcode原题我做过
第三题二段数有大佬帮我解释一下嘛 在本地跑可以按照题目意思跑通,为啥 放到牛客就超时了??
是我的输出格式问题吗
import javax.sound.midi.Soundbank;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<>();
        while (sc.hasNext()){
            String cur = sc.next();
            if(cur=="0") {

                break;
            }
            Long mul = 1L;
            Long num = Long.parseLong(cur);

            Long res = 1L;
            while(true){
                res = num*mul;
                String res2 = String.valueOf(res);
                int count =0;
                int i =0;
                boolean b =false;
                while(i<res2.length()-1){
                    if(count>1) break;



                    if(res2.charAt(i)!=res2.charAt(i+1)){
                        count++;
                    }
                    if(i==res2.length()-2 && count==1 ) b = true;
                    i++;

                }
                if(b){
                    list.add(cur+":"+res);
                    System.out.println(cur+":"+res);
                    break;
                }
                mul++;
            }
        }
        sc.close();
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

    }
}
本地结果为:

#蔚来笔试#
全部评论
害,我也超时,后来发现可能是用数字转字符串处理的问题,这个比较耗时。 结论:不能图省事啊,哭了
2 回复 分享
发布于 2022-07-29 00:14
格式有问题的话错误提示会提示格式有问题
点赞 回复 分享
发布于 2022-07-29 09:10
楼主很棒了,需要荣耀内推的话找我。加油!
点赞 回复 分享
发布于 2022-07-29 02:02
我也超时,试了下大的边界值9989就过不去了
点赞 回复 分享
发布于 2022-07-28 23:30

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
07-01 17:14
中北大学 Java
兄弟们是真是假
牛客46374834...:我在boss上投java岗从来没成功过
点赞 评论 收藏
分享
评论
1
4
分享

创作者周榜

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