一道简单的面试题:查询数组中出现两次的元素

楼主的同学的面试题 {1,1,1,2,2,3,3}把 2 ,3 取出来 因为出现了两次,这题用hashmap做

public class test {
    public static void main(String[] args) {
        Integer[] num = new Integer[]{1, 2, 2, 2, 3, 3, 4, 4};
        HashMap hashMap = find2(num);
        Set set = hashMap.keySet();
        for (Object object : set) {
            if ((int) hashMap.get(object) == 2) {
                System.out.println(object + "");
            }

        }
    }
    public static HashMap  find2(Integer[] num){
        HashMap map = new HashMap();
        for(int i = 0;i 
 

你可能感兴趣的:(渣滓学习路)