京东java笔试8.6,讨论一下,基本都是ac2道吧
京东别具一格啊,这么简单地题目,意思是就看简历了呗?应该读懂题目就人均AC两道吧
第二题优化半天 发现暴力可以直接过,91%的是因为个位数要去掉
好吧 有人私信我 我就贴下第二题 大佬轻喷
package leetcode.editor.cn.jd; import java.util.Scanner; public class test2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int m = in.nextInt(); int n = in.nextInt(); int count=0; for (int i = m; i <= n; i++) { boolean flag =false; if (i<10) continue; for (int j = 0; j < String.valueOf(i).length(); j++) { StringBuilder s = new StringBuilder(String.valueOf(i)); int newi = Integer.parseInt(s.deleteCharAt(j).toString()); System.out.println(newi); if (isReverse(newi)&&isPrime(newi)) { flag = true; break; } } if (flag) count++; } System.out.println(count); } private static boolean isReverse(int i) { String s = String.valueOf(i); for (int j = 0; j < s.length()/2; j++) { if (s.charAt(j)!=s.charAt(s.length()-1-j)) return false; } return true; } private static boolean isPrime(int i) { if (i<2) return false; for (int j = 2; j <= Math.sqrt(i) ; j++) { if (i%j==0) return false; } return true; } }