299. Bulls and Cows Medium

@problem@discussion
#Hash Table#String#Counting



1/**
2 * [299] Bulls and Cows
3 *
4 * You are playing the <a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a> game with your friend.
5 * You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:
6 * 
7 * 	The number of "bulls", which are digits in the guess that are in the correct position.
8 * 	The number of "cows", which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls.
9 * 
10 * Given the secret number secret and your friend's guess guess, return the hint for your friend's guess.
11 * The hint should be formatted as "xAyB", where x is the number of bulls and y is the number of cows. Note that both secret and guess may contain duplicate digits.
12 *  
13 * Example 1:
14 * 
15 * Input: secret = "1807", guess = "7810"
16 * Output: "1A3B"
17 * Explanation: Bulls are connected with a '|' and cows are underlined:
18 * "1807"
19 *   |
20 * "<u>7</u>8<u>10</u>"
21 * Example 2:
22 * 
23 * Input: secret = "1123", guess = "0111"
24 * Output: "1A1B"
25 * Explanation: Bulls are connected with a '|' and cows are underlined:
26 * "1123"        "1123"
27 *   |      or     |
28 * "01<u>1</u>1"        "011<u>1</u>"
29 * Note that only one of the two unmatched 1s is counted as a cow since the non-bull digits can only be rearranged to allow one 1 to be a bull.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	1 <= secret.length, guess.length <= 1000
35 * 	secret.length == guess.length
36 * 	secret and guess consist of digits only.
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/bulls-and-cows/
42// discuss: https://leetcode.com/problems/bulls-and-cows/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn get_hint(secret: String, guess: String) -> String {
48        String::new()
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_299() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.