Posted onInLeetCodeDisqus: Symbols count in article: 273Reading time ≈1 mins.
O(n) time O(n) space
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
classSolution { public: intsumOfUnique(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; } };