Leetcode 299. Bulls and Cows
来源:互联网 发布:数据出版相关论文 编辑:程序博客网 时间:2024/06/05 20:16
public class Solution { public String getHint(String secret, String guess) { int bull = 0, cow = 0; int[] cnt_se = new int[10]; int[] cnt_gu = new int[10]; // count bulls first // count cows using two arrays to save the count for each number appeared in secret and guess // e.g. cnt_secret[0] saves the number of 0s appeared in secret for (int i=0; i<secret.length(); i++) { if (secret.charAt(i) == guess.charAt(i)) bull++; else { cnt_se[secret.charAt(i)-'0']++; cnt_gu[guess.charAt(i)-'0']++; } } // chosse minimum count if a number appears in both secret and guess // b/c multiple cows count only once for (int j=0; j<10; j++) cow += Math.min(cnt_se[j], cnt_gu[j]); return bull + "A" + cow + "B"; }}
0 0
- [leetcode] 299. Bulls and Cows
- LeetCode || 299. Bulls and Cows
- LeetCode 299. Bulls and Cows
- Leetcode 299. Bulls and Cows
- LeetCode.299.Bulls and Cows
- LeetCode--299. Bulls and Cows
- 【LeetCode】299. Bulls and Cows
- [leetcode] 299. Bulls and Cows
- LeetCode *** 299. Bulls and Cows
- leetcode 299. Bulls and Cows
- LeetCode 299. Bulls and Cows
- LeetCode-299.Bulls and Cows
- Leetcode 299. Bulls and Cows
- 299.[leetcode]Bulls and Cows
- leetcode 299. Bulls and Cows
- LeetCode 299. Bulls and Cows
- 【leetcode】299. Bulls and Cows
- LeetCode 299. Bulls and Cows
- Mac SVN访问Windows服务器出错
- Tomcat学习2.2(简单的Servlet容器)
- 提高myEclipse的开发效率,设置
- 压缩感知科普
- echart展示图表
- Leetcode 299. Bulls and Cows
- windows10安装Scipy
- 中国压缩传感资源(China Compressive Sensing Resources)
- Spring 常用接口说明
- 每天一个linux命令(37):date命令
- 压缩感知(Compressive Sensing)学习之(二)
- OpenShift 自定义 OPENSHIFT_DOCUMENT_ROOT 变量,替换网站根目录路径!
- 四种比较简单的图像显著性区域特征提取方法原理及实现-----> AC/HC/LC/FT。
- C语言 return不等式