299. Bulls and Cows
来源:互联网 发布:淘宝供销 编辑:程序博客网 时间:2024/06/04 18:14
public class Solution {
public String getHint(String secret, String guess) {
if (secret == null || guess == null || secret.length() != guess.length()) {
return "";
}
int countA = 0;
int countB = 0;
int[] count = new int[10];
for (int i = 0; i < secret.length(); i++) {
if (secret.charAt(i) == guess.charAt(i)) {
countA++;
} else {
count[secret.charAt(i) - '0']++;
if (count[secret.charAt(i) - '0'] <= 0) {
countB++;
}
count[guess.charAt(i)- '0']--;
if (count[guess.charAt(i)- '0'] >= 0) {
countB++;
}
}
}
return String.valueOf(countA) + "A" + String.valueOf(countB) + "B";
}
}
public String getHint(String secret, String guess) {
if (secret == null || guess == null || secret.length() != guess.length()) {
return "";
}
int countA = 0;
int countB = 0;
int[] count = new int[10];
for (int i = 0; i < secret.length(); i++) {
if (secret.charAt(i) == guess.charAt(i)) {
countA++;
} else {
count[secret.charAt(i) - '0']++;
if (count[secret.charAt(i) - '0'] <= 0) {
countB++;
}
count[guess.charAt(i)- '0']--;
if (count[guess.charAt(i)- '0'] >= 0) {
countB++;
}
}
}
return String.valueOf(countA) + "A" + String.valueOf(countB) + "B";
}
}
0 0
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- Red5流服务器搭建(实现在线直播,流媒体视频播放和在线视频会议)
- Qt为rpath增加$ORIGING
- Openstack Fuel 9.0安装后网卡设置
- ipcs 查询进程间通信状态
- ThinkPHP3.2 Behavior随记
- 299. Bulls and Cows
- 2016 年 10月
- jQuery选择器大全
- Jquery Md5加密-Jquery.md5.js
- poj - 2406 Power Strings 【KMP】
- python:open/文件操作
- 第21节--python的GUI编程
- SAP QM数据库表清单
- Real-Time Rendering-第四章 Transforms(5)