# 唯一元素的和

import java.util.HashMap;
import java.util.Map;

/**
 * @author yagol
 * @date 上午12:07
 * @desc the description of this class
 **/
class Solution1748 {
    public int sumOfUnique(int[] nums) {
        HashMap<Integer, Integer> data = new HashMap<>();
        for (int num : nums) {
            data.put(num, data.getOrDefault(num, 0) + 1);
        }
        int res = 0;
        for (Map.Entry<Integer, Integer> entry : data.entrySet()) {
            if (entry.getValue() == 1) {
                res += entry.getKey();
            }
        }
        System.out.println(res);
        return res;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24