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

相关推荐

xwqlikepsl:感觉很厉害啊,慢慢找
点赞 评论 收藏
分享
04-18 15:58
已编辑
门头沟学院 设计
kaoyu:这一看就不是计算机的,怎么还有个排斥洗碗?
点赞 评论 收藏
分享
评论
点赞
5
分享

创作者周榜

更多
牛客网
牛客企业服务