全部评论
写出你们所有的解法呢,复杂度尽量低的!🤔
给大佬们献丑了,有啥问题及时指出,谢谢~
用hashmap,如果有互斥的值,将互斥的键的值加1,最后计算键的值大于1的数量 public static int Maxcount(int p,int []array){
if (array==null||array.length==0||p<=1)
return 0;
HashMap<Integer,Integer>map1=new HashMap<>();
for (int i=0;i<array.length;i++){
map1.put(array[i],!map1.containsKey(array[i])?1:map1.get(array[i])+1);
}
int count=0;
for (int i=0;i<array.length;i++) {
if (map1.containsKey(array[i] * p)) {
map1.put(array[i], map1.get(array[i]) + 1);
map1.put(array[i] * p, map1.get(array[i] * p) + 1);
}
}
for (int temp:map1.keySet())
if (temp>1)
count++;
return count;
}
相关推荐


游卡
| 校招
| 超多精选岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享