forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
32 lines (31 loc) · 723 Bytes
/
solution.cpp
File metadata and controls
32 lines (31 loc) · 723 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
27
28
29
30
31
32
class Solution
{
public:
string getHint(string secret, string guess)
{
string result;
int c = 0;
for(int i=0;i<secret.size();i++)
{
if(secret[i] == guess[i])
c++;
}
result = to_string(c)+"A";
vector<int> tableS(10),tableG(10);
for(int i=0;i<secret.size();i++)
{
tableS[secret[i]-'0']++;
tableG[guess[i]-'0']++;
}
int t = 0;
for(int i=0;i<10;i++)
{
if(tableS[i] > tableG[i])
t += tableG[i];
else
t += tableS[i];
}
result += to_string(t-c) + "B";
return result;
}
};