import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param nums int整型一维数组
     * @return int整型
     */

    public int remove_duplicates_v3 (int[] nums) {

        // write code here
        int index = -1;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);
        }
        int total = 0;
        for (Map.Entry<Integer, Integer> myMap : map.entrySet()) {
            if (myMap.getValue() > 3) {
                total += 3;
            } else {
                total += myMap.getValue();
            }
        }
        return total;
    }
}

本题主要就是考察数组重复元素的统计,所用编程语言是java。

本题对于重复元素的统计,超过3次的设置为3次,不超过3次就是数组重复元素次数