Nice solution! It is easy and concise, In my solution, I use two unordered_map ,also solve the problem. But it is complex!

class Solution {
public:
string getHint(string secret, string guess) {
int len = secret.length();
unordered_map<int, int> m;//key represents the number，value represents the times of the number appearing
unordered_map<int, int> mm;
int bull = 0, cow = 0;
string res = "";
for (int i = 0; i<len; i++)
{
if (secret[i] == guess[i])//cow number
bull++;
else
{
m[secret[i] - '0']++;
mm[guess[i] - '0']++;
}
}
for (int i = 0; i<len; i++)
{
if (m.find(guess[i] - '0') != m.end())//m has the number
{
if (mm[guess[i] - '0']>0&&m[guess[i] - '0']>0)
{
cow++;
mm[guess[i] - '0']--;
m[guess[i] - '0']--;
}
}
}
res = to_string(bull) + "A" + to_string(cow) + "B";
return res;
}
};