Posted on

Description

Submission

class Solution {
public:
    int sumOfUnique(vector<int>& nums) {
        map<int, int> Map;
        for(auto x: nums) {
            Map[x]++;
        }
        
        int ret = 0;
        for(auto p: Map) {
            if(p.second == 1) {
                ret += p.first;
            }
        }
        return ret;
    }
};
class Solution {
    int cnt[101];
public:
    int sumOfUnique(vector<int>& nums) {
        
        for(auto x: nums) {
            cnt[x]++;
        }
        
        int ret = 0;
        for(int i = 1; i < 101; ++i) {
            if(cnt[i] == 1) {
                ret += i;
            }
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *