当前位置:网站首页>Find the ArrayList < double > with the most occurrences in ArrayList < ArrayList < double >
Find the ArrayList < double > with the most occurrences in ArrayList < ArrayList < double >
2022-07-24 06:10:00 【A little cute C】
public static ArrayList<Double> candidate (ArrayList<ArrayList<Double>> list) // Find the number that appears the most in the array
{
// map Of key Store the numbers in the array ,value Store the number of occurrences of this number
HashMap<ArrayList<Double>, Integer> map = new HashMap<ArrayList<Double>, Integer>();
for(int i = 0; i < list.size(); i++)
{
if(map.containsKey(list.get(i)))
{
int formerValue = map.get(list.get(i));
map.put(list.get(i), formerValue + 1); // The number of times this number appears plus 1
}
else
{
map.put(list.get(i), 1); // This number appears for the first time
}
}
Collection<Integer> count = map.values();
// find map Of value The maximum , That is, the number of times that the most numbers appear in the array
int maxCount = Collections.max(count);
ArrayList<Double> maxNumber = new ArrayList<>();
for(Map.Entry<ArrayList<Double>, Integer> entry : map.entrySet())
{
// obtain value by maxCount Of key, That is, the number that appears the most times in the array
if(entry.getValue() == maxCount)
{
maxNumber = entry.getKey();
}
}
return maxNumber;
}边栏推荐
- GCC 中__attribute__((constructor)和__attribute__(((destructor))的注意事项。
- Vsual studio 2013 environment UDP multicast
- systemctl + journalctl
- JUC concurrent programming foundation (9) -- thread pool
- Native JS magnifying glass effect
- Openwrt quick configuration Samba
- Day2 websocket+ sort
- KMP代码分布详解
- 【树莓派4B】七、远程登录树莓派的方法总结XShell,PuTTY,vncServer,Xrdp
- 精确计算时间延迟VxWorks 时间戳 详解
猜你喜欢
![[MYCAT] MYCAT installation](/img/52/2f77ed64b2ed4e9297acaa8362e194.png)
[MYCAT] MYCAT installation

Use QT to connect to MySQL and create table numbers, write data, and delete data
![[principles of database system] Chapter 4 advanced database model: Unified Modeling Language UML, object definition language ODL](/img/51/7387c73148ee7bd1034bb6e77af7f0.png)
[principles of database system] Chapter 4 advanced database model: Unified Modeling Language UML, object definition language ODL

Foundation of JUC concurrent programming (7) -- multithread lock

MySql下载,及安装环境设置

Statistical learning methods (2nd Edition) Li Hang Chapter 22 summary of unsupervised learning methods mind mapping notes
![[activiti] gateway](/img/8c/c89ec6c4c5871a32218ddadfd8beba.png)
[activiti] gateway

论文阅读-Endmember-Guided Unmixing Network (EGU-Net) 端元指导型高光谱解混网络
![[activiti] process example](/img/77/63d7d1ea8c634fb3741383f40f38e7.png)
[activiti] process example

Accessing a two-dimensional array with a pointer
随机推荐
Qt新手入门级 计算器加、减、乘、除、应用
Synergy LAN realizes multi host shared keyboard and mouse (AMD, arm)
【FatFs】手动移植FatFs,将SRAM虚拟U盘
[MYCAT] related concepts of MYCAT
HoloLens 2 中文开发文档 MRTK v2
[activiti] group task
【树莓派4B】七、远程登录树莓派的方法总结XShell,PuTTY,vncServer,Xrdp
vsual studio 2013环境 Udp组播
【数据库系统原理】第五章 代数和逻辑查询语言:包、扩展操作符、关系逻辑、关系代数与Datalog
常见AR以及MR头戴显示设备整理
Unity Shader从内置渲染管线迁移到URP
Unity 3D帧率统计脚本
Write the list to txt and directly remove the comma in the middle
day1-jvm+leetcode
CRC-16 Modbus代码
论文阅读-Endmember-Guided Unmixing Network (EGU-Net) 端元指导型高光谱解混网络
QT novice entry level calculator addition, subtraction, multiplication, division, application
MySql下载,及安装环境设置
Answers and analysis of some after-school exercises in signals and systems (Wujing)
JDBC进阶—— 师承尚硅谷(DAO)