299. Bulls and Cows#2(Done)
来源:互联网 发布:php源码 虚拟股票 编辑:程序博客网 时间:2024/05/24 01:39
Solution
public class Solution { public String getHint(String secret, String guess) { int[] s = new int[26]; int[] g = new int[26]; int bulls = 0; int cows = 0; for (int i = 0; i < secret.length(); i++) { if (secret.charAt(i) == guess.charAt(i)) { bulls++; } else { s[secret.charAt(i) - '0']++; g[guess.charAt(i) - '0']++; } } for (int i = 0; i < 26; i++) { cows += Math.min(s[i], g[i]); } return bulls + "A" + cows + "B"; }}
Problem#1
- 效率太低
- Character.getNumericValue方法
- 两种更优秀的方法,一种两个数组,少很多次加法;一种一个数组
0 0
- 299. Bulls and Cows#2(Done)
- 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
- Should VBO be unbound before calling glDeleteBuffers?
- SDNU 1126 Integer Inquiry
- 多思多问-----ajax的使用
- 爬虫初体验,解析网页Table
- 【转帖】OpenGL的版本历史和发展 (2013-07-24 14:57:28)
- 299. Bulls and Cows#2(Done)
- Ubuntu16.04 LTS 版安装VMwareTools的步骤和没法挂载目录问题的解决
- 201612-1 试题名称:最大波动(100分)ccf认证
- ListView的下拉刷新和上拉加载
- 配置文件类 Properties
- 在Kali Linux下实战Nmap的秘诀
- java - 继承 ,重写
- 水表项目 水表数字识别率分析
- Nao机器人学习(二)