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

相关推荐

07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
昨天 11:05
门头沟学院 运营
点赞 评论 收藏
分享
评论
点赞
5
分享

创作者周榜

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