mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 09:54:57 +08:00
Add solution 0299
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
# [299. Bulls and Cows](https://leetcode-cn.com/problems/bulls-and-cows/)
|
||||
# [299. Bulls and Cows](https://leetcode.com/problems/bulls-and-cows/)
|
||||
|
||||
|
||||
## 题目
|
||||
@ -72,12 +72,14 @@ Output: "1A0B"
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 计算下标一致并且对应下标的元素一致的个数,即x
|
||||
- secret和guess分别去除x个公牛的元素,剩下secret和guess求共同的元素个数就是y
|
||||
- 把x, y转换成字符串,分别与"A"和"B"进行拼接返回结果
|
||||
- 计算下标一致并且对应下标的元素一致的个数,即 x
|
||||
- secret 和 guess 分别去除 x 个公牛的元素,剩下 secret 和 guess 求共同的元素个数就是 y
|
||||
- 把 x, y 转换成字符串,分别与 "A" 和 "B" 进行拼接返回结果
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
|
||||
package leetcode
|
||||
|
||||
import "strconv"
|
||||
|
Reference in New Issue
Block a user