2024-03-10发表2025-01-15更新LeetCode每日一题几秒读完 (大约94个字)0次访问299. 猜数字游戏猜数字游戏 难度: medium 原始链接: https://leetcode.cn/problems/bulls-and-cows 标签: 哈希 解法一: 哈希go12345678910111213141516171819func getHint(secret string, guess string) string { bulls := 0 cows := 0 sCount := make([]int, 10) gCount := make([]int, 10) n := len(secret) for i := 0; i < n; i++ { if secret[i] == guess[i] { bulls++ } else { sCount[secret[i]-'0']++ gCount[guess[i]-'0']++ } } for i := 0; i < 10; i++ { cows += min(sCount[i], gCount[i]) } return strconv.Itoa(bulls) + "A" + strconv.Itoa(cows) + "B"} 299. 猜数字游戏https://wuhunyu.top/leetcode/2024/03/bulls-and-cows/index.html作者wuhunyu发布于2024-03-10更新于2025-01-15许可协议#哈希