Bulls and Cows 带测试版
来源:互联网 发布:程序员的英语单词 编辑:程序博客网 时间:2024/05/21 11:01
import java.util.*;public class Solution299 { public static String getHint(String secret, String guess) { char[] se = secret.toCharArray(); char[] gu = guess.toCharArray(); int len = se.length; int bull = 0; int cow = 0; Map<Character, Integer> seHas = new HashMap<haracter, Integer>(); for (int i = 0; i < len; i++) { if (!seHas.containsKey(se[i])) { seHas.put(se[i], 1); } else { seHas.put(se[i], seHas.get(se[i]) + 1); } } Boolean[] b = new Boolean[len]; for (int i = 0; i < len; i++) { if (se[i] == gu[i]) { b[i] = true; seHas.put(gu[i], seHas.get(gu[i])-1); cow++; }else { b[i] = false; } } for (int j = 0; j < len; j++) { if(b[j] == false && seHas.get(gu[j])!=null && seHas.get(gu[j])>0) { bull ++; seHas.put(gu[j], seHas.get(gu[j])-1); } } return cow + "A" + bull + "B"; } public static void main(String[]args) { System.out.println(getHint("1807","7810")); }}
0 0
- Bulls and Cows 带测试版
- [LeetCode]Bulls and Cows
- [LeetCode] Bulls and Cows
- LeetCode Bulls and Cows
- [leetcode299]Bulls and Cows
- Bulls and Cows
- leetcode | Bulls and Cows
- Bulls and Cows
- LeetCode:Bulls and Cows
- LeetCode -- Bulls and Cows
- leetcode: Bulls and Cows
- [leetcode]Bulls and Cows
- Bulls and Cows
- Bulls and Cows
- 299. Bulls and Cows
- Bulls and Cows-LeetCode
- Leetcode191: Bulls and Cows
- [Leetcode]Bulls and Cows
- Power of Three 带测试版
- MT6752/32平台 Android L版本驱动移植
- Maximum Size Subarray Sum Equals k 带测试版
- u-boot-1.1.6 移植
- java集合(二)
- Bulls and Cows 带测试版
- UIImage 切圆形图片方法
- 【Bash百宝箱】shell中如何进行数学运算
- 欢迎使用CSDN-markdown编辑器
- BMFont位图制作工具的使用
- Mysql常用函数
- Delphi 用idhttp 获取网页源码
- GPUImage实战问题解决
- 当我们说数据挖掘的时候我们在说什么