Simple C++ Solution using map


  • 0
    K
        map<int, int> a;
        int countA = 0, countB = 0;
        for (int i = 0; i<secret.size(); i++)
        {
            if ( secret[i] == guess[i] ) countA++;
            a[secret[i]]++;
        }
         for (int i = 0; i<secret.size(); i++)
        {
            if (a[guess[i]]-- > 0) countB++;
        }
        return to_string(countA) + 'A' + to_string(max(countB-countA,0)) + 'B';

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.