forked from dhyey6602/leetcode_september
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10thSep.cpp
30 lines (29 loc) · 865 Bytes
/
10thSep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
string getHint(string secret, string guess) {
map<char, int> dicti,dicti1;
int bull=0,cow=0;
for(int i=0;i<secret.size();i++)
{
if(dicti.find(secret[i])==dicti.end())
dicti[secret[i]]=1;
else
dicti[secret[i]]++;
if(dicti1.find(guess[i])==dicti1.end())
dicti1[guess[i]]=1;
else
dicti1[guess[i]]++;
if(secret[i]==guess[i])
bull++;
}
for(auto itr=dicti.begin();itr!=dicti.end();++itr)
{
if(dicti1.find(itr->first)!=dicti1.end())
{
cow+=min(itr->second,dicti1[itr->first]);
}
}
string ans=to_string(bull)+'A'+to_string(cow-bull)+'B';
return ans;
}
};