京东笔试 回文素数

只A了36%,没有找到原因。。
不是超时,是答案错误。。
求各位帮我看一下,,,费解呀

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int res = 0;
        for(int i = n;i<=m;i++){
            if(checkValid(i)) res++;
        }
        System.out.println(res);
        sc.close();
    }
    public static boolean checkValid (int num){
        String str = String.valueOf(num);
        for(int i = 0;i<str.length();i++){
            String temp = str.substring(0,i)+str.substring(i+1);
            int left = 0;
            while(temp.charAt(left)=='0'&&left<=temp.length()-1) left++;
            if(left>=temp.length()) continue;
            String curr = temp.substring(left);
            if(isPla(curr)&& strPrime(curr)) return true;
        }
        return false;

    }
    public static boolean strPrime(String str){
        int num = Integer.valueOf(str);
        return isPrime(num);
    }
    public static boolean isPrime (int num){
        if(num < 2) return false;
        if(num == 2) return true;
        int sqrt = (int) Math.sqrt(num);

        for(int i=2;i <= sqrt; i++){
            if(num%i==0) return false;
        }
        return true;

    }

    public static boolean isPla(String temp){
        int left = 0;
        int right = temp.length()-1;

        if(temp.length()==1) return true;
        while(left<right){
            char a = temp.charAt(left);
            char b = temp.charAt(right);
            if(a == b){
                left++;
                right--;
            }else{
                return false;
            }
        }
        return true;
    }

}
#笔试题目##京东#
全部评论
我才18
1 回复 分享
发布于 2020-08-07 00:55
我也暴力,不过只有27😂
1 回复 分享
发布于 2020-08-06 22:04
请问题型是咋样的??全编程还是有选择呢
点赞 回复 分享
发布于 2020-08-23 09:41
可以用自己的IDE吗还是必须线上系统的?
点赞 回复 分享
发布于 2020-08-20 18:16
小姐姐,我之前也是36,后来改到了91,原因是删除前置0的那里代码有了问题,你把这个地方改成这样就可以了while(left<=temp.length()-1 && temp.charAt(left)=='0') left++;
点赞 回复 分享
发布于 2020-08-08 23:19
我开始36,加了循环条件是i<sqrt&&i<num就a了
点赞 回复 分享
发布于 2020-08-07 15:06
如果n小于10,m大于10,就把n置为10,还有要解析前导0的情况
点赞 回复 分享
发布于 2020-08-07 14:56
我想问一下,我写完代码后只测了自测数据通过了,然后点击了那个保存按钮,没有测全部数据,后台会帮我测全部数据吗?第一次用赛马那个平台,不会用,我一直按运行一直在跑自测数据,我还以为这个是平台自动帮你测的,看到你们个个AC多少多少,我感觉自己是不是白做了?😂😂😂
点赞 回复 分享
发布于 2020-08-07 10:56
**血亏,我说怎么一直是18,我一直看的是有多少回文数,而不是回文素数,我日加个判断也许就过去了。。。。。。
点赞 回复 分享
发布于 2020-08-07 10:22
我也36 奇怪得数字
点赞 回复 分享
发布于 2020-08-07 10:17
while(temp.charAt(left)=='0'&&left<=temp.length()-1) left++; 你这个语句不会越界吗?如果都是0的话
点赞 回复 分享
发布于 2020-08-07 09:11
同36  加了去第一位0之后没有变化 😂
点赞 回复 分享
发布于 2020-08-07 00:36
10110,去掉第一位0110是,但数字应该是110不是
点赞 回复 分享
发布于 2020-08-06 23:23
其实可以打表😂
点赞 回复 分享
发布于 2020-08-06 22:56
之前也是36,我把判断前置0的代码删掉,到了91
点赞 回复 分享
发布于 2020-08-06 22:41
1不是素数,判断加上后即可
点赞 回复 分享
发布于 2020-08-06 22:30
我这儿有一个C++的代码,你要看吗,Java太长了
点赞 回复 分享
发布于 2020-08-06 22:29
+1
点赞 回复 分享
发布于 2020-08-06 22:18
同36%
点赞 回复 分享
发布于 2020-08-06 22:16
我也是36,很怪异 ,我查了半小时还是没想起来漏了什么
点赞 回复 分享
发布于 2020-08-06 22:12

相关推荐

找工作勤劳小蜜蜂:自我描述部分太差,完全看不出想从事什么行业什么岗位,也看不出想在哪个地区发展,这样 会让HR很犹豫,从而把你简历否决掉。现在企业都很注重员工稳定性和专注性,特别对于热爱本行业的员工。 你实习的工作又太传统的it开发(老旧),这部分公司已经趋于被淘汰,新兴的互联网服务业,比如物流,电商,新传媒,游戏开发和传统的It开发有天然区别。不是说传统It开发不行,而是就业岗位太少,基本趋于饱和,很多老骨头还能坚持,不需要新血液。 工作区域(比如长三角,珠三角,成渝)等也是HR考虑的因素之一,也是要你有个坚定的决心。否则去几天,人跑了,HR会被用人单位骂死。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
7
分享

创作者周榜

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