classSolution {publicStringgetHint(String secret,String guess) {int bulls =0;int cows =0;int[] secretCount =newint[10];int[] guessCount =newint[10];for (int i =0; i <secret.length(); i++) {if (secret.charAt(i) ==guess.charAt(i)) { bulls++; } else { secretCount[secret.charAt(i) -'0']++; // record number count guessCount[guess.charAt(i) -'0']++; } }for (int i =0; i <10; i++) { cows +=Math.min(secretCount[i], guessCount[i]); }return bulls +"A"+ cows +"B"; }}/*bulls correct position. x is the number of bullscows right number in secret, but in wrong position , can rearrange to be bulls, y is the number of cowssecret(ans), guess, return hint, xAyBcompare two String, if match bulls++else record in counting array, countS[i]++, countG[i]++ final for (entire countS[]) { cows += Math.min(countS[i], countG[i]) } ex: 1123 b 0111 bulls = 1 others not matches, but has common 1'num in both counter time: O(n), n is min(secret'len, 10) space: O(1)*/