You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called “bulls”) and how many digits match the secret number but locate in the wrong position (called “cows”). Your friend will use successive guesses and hints to eventually derive the secret number.
For example:
Secret number: "1807"
Friend's guess: "7810"
Hint: 1 bull and 3 cows. (The bull is 8, the cows are 0, 1 and 7.)
Write a function to return a hint according to the secret number and friend’s guess, use A to indicate the bulls and B to

本文介绍了Bulls and Cows游戏的规则,即玩家猜测一个秘密数字,根据提示(正确位置的数字数量和错误位置的数字数量)来逐步接近正确答案。例如,当秘密数字为1807,朋友猜的是1087时,返回的提示应为'1A3B'。游戏允许数字重复,如朋友猜1101,正确的提示应为'1A1B'。确保秘密数字和猜测数字长度相等。
订阅专栏 解锁全文
279

被折叠的 条评论
为什么被折叠?



