#力扣 LeetCode面试题 16.15. 珠玑妙算 @FDDLC
作者:互联网
题目描述:
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]};
}
}
标签:面试题,String,16.15,int,力扣,toCharArray,128,new 来源: https://blog.csdn.net/liuxc324/article/details/115298548