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
秋招专场
校招火热招聘中
官网直投

相关推荐

头像
不愿透露姓名的神秘牛友
05-27 11:41
已编辑
点赞 评论 收藏
转发
巨人网络 测试 总包20左右
点赞 评论 收藏
转发
点赞 5 评论
分享
牛客网
牛客企业服务