题目描述:
https://leetcode-cn.com/problems/master-mind-lcci/
Java代码:
class Solution {
public int[] masterMind(String S, String G) {
char[] s=S.toCharArray(),g=G.toCharArray(),color={'R','G','B','Y'};
int[] cnts=new int[128],cntg=new int[128];
for(int i=0;i<4;cnts[s[i]]++,cntg[g[i]]++,i++)if(s[i]==g[i])cnts[0]++;
for(char e:color)cnts[1]+=Math.min(cnts[e],cntg[e]);
return new int[]{cnts[0],cnts[1]-cnts[0]};
}
}