Posted on

Description

Submission

class Solution {
public:
    string getHint(string secret, string guess) {
        vector<int> s(10, 0);
        vector<int> g(10, 0);
        int nBull = 0, nCow = 0;
        for(int i = 0; i < secret.size(); ++i) {
            if(secret[i] == guess[i]) nBull++;
            else {
                s[secret[i]-'0']++;
                g[guess[i] - '0']++;
            }
        }
        for(int i = 0; i < 10; ++i) {
            nCow += min(s[i], g[i]);
        }
        stringstream ss;
        ss << nBull << 'A' << nCow << 'B'; 
        return ss.str();
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *