leetcode 299 Bulls and Cows C++
来源:互联网 发布:matdem软件下载 编辑:程序博客网 时间:2024/06/05 20:45
也是参考了别人的做法。
两个大小为10的数组。
相同位置相同则直接将bull+1;
否则把数字存入数组。
然后把每个位置较小的数累加到cow里面即可。
string getHint(string secret, string guess) { int bullNum = 0; int cowNum = 0; vector<int> bullArray(10,0); vector<int> cowArray(10,0); for(int i = 0;i<secret.size();i++){ if(secret[i]==guess[i]){ bullNum++; } else { bullArray[secret[i] - '0']++; cowArray[guess[i] - '0']++; } } for(int i = 0;i<10;i++){ cowNum += min(bullArray[i],cowArray[i]); } return to_string(bullNum) + 'A' + to_string(cowNum) + 'B'; }
0 0
- leetcode 299:Bulls and Cows
- Bulls and Cows leetcode 299
- 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
- LeetCode 299 Bulls and Cows
- LeetCode[299] Bulls and Cows
- Leetcode 299 Bulls and Cows
- 【机房重构】结账—触发器应用
- Scala 无参数方法和统一访问原则
- 详解Linux中的进程描述符task_struct
- Android六大类进程介绍
- 【阅读笔记】移动APP测试实战--第一章
- leetcode 299 Bulls and Cows C++
- C++实验7-数组素数排序
- AngulaJs显示隐藏
- MVC框架
- 第15周实践项目-范型程序设计(1)
- MySQL 执行计划里的rows
- 如何学习Windows编程
- 第十一周项目1-点-圆-圆柱类族的设计(2)
- yeoman-web脚手架工具