Wrong charArray solutions?


  • -2
    L
    public class Solution {
    public String getHint(String secret, String guess) {
        int a = 0;
        int b = 0;
        for (int i = 0; i < secret.length(); i++) {
            if (secret.charAt(i) == guess.charAt(i)) {
                a++;
            } else {
                b++;
            }
        }
        return a + "A" + b + "B";
    }
    

    }


  • 0
    J

    You may misunderstand this question.
    "cows" must be the number which EXIST in secret string first, and in wrong position.

    For example,
    secret = 1234
    guess = 1245.
    the bulls are "1" and "2", cows is only "4", which should return 2A1B.
    but your solution will return 2A2B.


  • 0
    L

    got it....
    thks


Log in to reply
 

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