这种暴力代码10%是不是就是因为时间不够了 public class test3 { public static boolean check(int m) { String reslut=Integer.toBinaryString(m); StringBuffer sb= new StringBuffer(reslut); sb.reverse(); int count=0; for(int i=0;i<reslut.length();i++) { if(reslut.charAt(i)==sb.charAt(i)) { count++; } } if(count==reslut.length()) { return true; }else { return false; } } public static void test(int n) { if(n<1 || n>Math.pow(10, 10)) { return; } int temp=0; for(int i=0;i<=n;i++) { if(check(i)) { temp++; } } System.out.println(temp); } public static void main(String[] args) { Scanner s= new Scanner(System.in); while(true) { int n= s.nextInt(); test(n); } } }
点赞 评论

相关推荐

牛客网
牛客企业服务