-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path299.cpp
More file actions
26 lines (26 loc) · 688 Bytes
/
299.cpp
File metadata and controls
26 lines (26 loc) · 688 Bytes
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
class Solution {
public:
string getHint(string secret, string guess) {
vector<int> arr(10,0),check(10,0);
for(auto x: secret)
arr[x-'0']++;
int a = 0, b = 0, n = guess.size();
for(int i=0;i<n;i++){
if(guess[i]==secret[i]){
a++;
arr[secret[i]-'0']--;
}
else{
check[guess[i]-'0']++;
}
}
for(int i=0;i<10;i++){
if(check[i]!=0){
if(arr[i]!=0)
b += min(check[i],arr[i]);
}
}
string res = to_string(a) + "A" + to_string(b) + "B";
return res;
}
};