[LeetCode]Bulls and Cows
public class Solution { public String getHint(String secret, String guess) { int[] s = new int[10]; int[] g = new int[10]; int A = 0; int B = 0; for (int i = 0; i < secret.length(); i++) { if(secret.charAt(i) == guess.charAt(i)) { A ++; } else { s[(int)secret.charAt(i) - (int)'0'] ++; g[(int)guess.charAt(i) - (int)'0'] ++; } } for (int i = 0; i < 10; i++) { B += Math.min(s[i], g[i]); } return String.valueOf(A) + "A" + String.valueOf(B) + "B"; } }