Game of Thrones - I

  • + 0 comments

    Here is my c++ solution : explanation here : https://youtu.be/yhSaL48IHds

    solution 1 :

    string gameOfThrones(string s) {
        map<char, int> mp;
        for(int i = 0; i < s.size(); i++){
            if(mp[s[i]] != 0){
                mp[s[i]]--;
                if(mp[s[i]] == 0) mp.erase(s[i]);
            }
            else mp[s[i]]++;
        }
        if(mp.size() > 1) return "NO";
        return "YES";
    }
    

    solution 2 :

    string gameOfThrones(string s) {
        map<char, int> mp;
        for(int i = 0; i < s.size(); i++){
            if(mp[s[i]] == 1)  mp.erase(s[i]);
            else mp[s[i]]++;
        }
        if(mp.size() > 1) return "NO";
        return "YES";
    }