蔚来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)); } } }本地结果为: