Skip to content

Commit 42bf23c

Browse files
committed
299
1 parent bb11b93 commit 42bf23c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

299.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
string getHint(string secret, string guess) {
4+
int bull=0;
5+
int cow=0;
6+
7+
map<int,int>mp;
8+
for(int i=0;i<secret.length();i++){
9+
if(guess[i]==secret[i]){
10+
bull++;
11+
guess[i]='A';
12+
secret[i]='B';
13+
}
14+
else{
15+
mp[secret[i]]++;
16+
}
17+
}
18+
19+
for(int i=0;i<guess.length();i++){
20+
if(mp.find(guess[i])!=mp.end() && mp[guess[i]]>0 ){
21+
mp[guess[i]]--;
22+
cow++;
23+
}
24+
}
25+
string str=to_string(bull) + 'A' + to_string(cow) + 'B';
26+
27+
return str;
28+
29+
30+
}
31+
};

0 commit comments

Comments
 (0)