我有int[]
以下内容的输入:
[5, 65, 22, 1, 58, 5, 69, 12, 1, 22, 22, 58, 12, 54, 89]
使用Map<Object, AtomicInteger>
,我将其转换为以下对象:
{1=2, 65=1, 5=2, 69=1, 22=3, 58=2, 12=1}
换句话说,我正在计算动态数组的重复元素。
现在我需要找出最大和最小出现次数,我真的被困在进一步的步骤上。
重复元素类的代码如下:
public Map<Object, AtomicInteger> countRepeatingElements(int[] inputArray) {
ConcurrentMap<Object, AtomicInteger> output =
new ConcurrentHashMap<Object, AtomicInteger>();
for (Object i : inputArray) {
output.putIfAbsent(i, new AtomicInteger(0));
output.get(i).incrementAndGet();
}
return output;
}