0%

1748. Sum of Unique Elements

O(n) time O(n) space

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int sumOfUnique(vector<int>& nums) {
unordered_map<int, int> m;
for (int x : nums) {
++m[x];
}
int res = 0;
for (auto &[x, cnt] : m) {
if (cnt == 1) {
res += x;
}
}
return res;
}
};