299. Bulls and Cows
来源:互联网 发布:巨人网络借壳a股上市 编辑:程序博客网 时间:2024/03/29 04:48
class Solution {public: string getHint(string secret, string guess) { int n=secret.size(); if(n==0) return "0A0B"; int acount=0; for(int i=0;i<n;i++) { if(secret[i]==guess[i]) acount++; } map<char,int> m; for(int i=0;i<n;i++) { m[secret[i]]++; } int bcount=0; for(int i=0;i<guess.size();i++) { if(m.find(guess[i])!=m.end()) { if(m[guess[i]]>0) { bcount++; m[guess[i]]--; } } } bcount-=acount; return to_string(acount)+"A"+to_string(bcount)+"B"; }};
1 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
- 魔术方法之简单实例
- window bat xcopy用法示例
- Android:使用HttpClient访问HTTP/HTTPS服务器
- An internal error occurred during: "Updating Maven Project".Unsupported IClasspathEntry kind=4问题解决备忘
- 交换两个变量的(六种)方法分析
- 299. Bulls and Cows
- 最新常用的Google 高级搜索技巧
- 关于ssh框架action传值中文乱码问题
- java定时操作之Timer和TimerTas
- Eclipse 在异常关闭后,启动闪退的解决办法
- JAVA面向对象三大特征
- Xcode清除缓存及多余证书
- IPC机制学习导航
- 常用的节点类型常量