4.24 腾讯笔试情况

1、从上往下读数排序
2、删除非质数下标输出最后元素
3、士兵分组后进攻防守值最小差
4、链表环最小字典序
5、股票最大持有余额#投票##腾讯##笔试题目#
全部评论
https://tans.fun/archives/tecent-2022-exam 写了一篇题解,欢迎评论😀
9 回复 分享
发布于 2022-04-24 22:24
第二题只能过70多,还能咋优化兄弟们 static Set<Integer> set=new HashSet<>();     public static int getNumber(int[] a){         List<Integer> list=new ArrayList<>();         List<Integer> help=new ArrayList<>();         for(int i=0;i<a.length;i++){             list.add(a[i]);             help.add(a[i]);             if(!isPrime(i+1)){                 set.add(i+1);             }         }         while(true){             int count=0;             int n=list.size();             for(int i=0;i<n;i++){                 if(set.contains(i+1)){                     help.remove(i-count);                     count++;                 }             }             list=help;             if(list.size()==1) break;         }         return list.get(0);     }     public static boolean isPrime(int n){         if(n==1) return false;         for(int i=2;i<=Math.sqrt(n);i++){             if(n%i==0){                 return false;             }         }         return true;     }
点赞 回复 分享
发布于 2022-04-24 22:27

相关推荐

04-08 13:31
已编辑
门头沟学院 前端工程师
D0cC:京东营收1万多亿人民币,阿里9000多亿,虽然他俩利润都没腾讯和字节多,但是很恐怖了啊,负担了多少打工人的薪水
投递拼多多集团-PDD等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
5
分享

创作者周榜

更多
牛客网
牛客企业服务