标签:amp col int java for style length and secret
class Solution { public String getHint(String secret, String guess) { int bull = 0; int cow = 0; int[] mem = new int[10]; for(int i =0; i<secret.length();i++){ if(secret.charAt(i)==guess.charAt(i)){ bull++; }else{ if (mem[secret.charAt(i)-‘0‘]++ < 0){ cow++; } if (mem[guess.charAt(i)-‘0‘]-- > 0){ cow++; } } } return bull+"A"+cow+"B"; } }
bulls & cows, 用数组保存见过的数字的次数
标签:amp col int java for style length and secret
原文地址:https://www.cnblogs.com/zg1005/p/11922928.html