Frustration Why the C++ way Run Code Pass but Submit Solution Wrong


  • 0
    I

    Frustration Why the C++ way Run Code Pass but Submit Solution Wrong
    ···

    class Solution {
    public:
    string getHint(string secret, string guess) {
        int bulls = 0;
        int cows = 0;
        vector<int> numbers(10, 0);
        for (int i = 0; i < secret.length(); i++)
        {
            if (secret[i] == guess[i])
            {
                bulls++;
            }
            else 
            {
                if (numbers[static_cast<int>(secret[i])]++ < 0)
                {
                    cows++;
                }
                
                if (numbers[static_cast<int>(guess[i])]-- > 0)
                {
                    cows++;
                }
            }
        }
        return to_string(bulls) + "A" + to_string(cows) + "B";
    }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.