My C# that beats 8.87%, improve later


  • 0
    K
    public class Solution {
        public string GetHint(string secret, string guess) {
            int all = 0;
            bool[] isUsed = new bool[secret.Length];
            int bulls = 0;
            bool[] isUsedG = new bool[guess.Length];
            for(int i = 0; i < secret.Length; i++){
                
                for(int j = 0; j < guess.Length; j++){
                    if(guess[j] == secret[i] && isUsed[i] != true && isUsedG[j] != true) 
                    {
                        all++;
                        isUsed[i] = true;
                        isUsedG[j] = true;
                                      
                    }
                }
                if(secret[i] == guess[i]) bulls++;
            }
            Console.WriteLine(all);
            string result = bulls.ToString() + 'A' + (all-bulls).ToString() + 'B';    
            return result;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.