[C#] Brutal force workaround without Regex, Slow but surprisedly beats 25%


  • 0

    Regex check might be the fastest answer to this question.

    But it's hard to write to regex check in C# when it comes to close book scenarios.(tips would be appreciated)

    So I wrote the following brutal force code:

    Be careful to the follow-up questions, like "Now I assume the 5 'X's should return false, is this code a good solution?" No, stick with regex check

        public bool CheckRecord(string s) {
            
            int aCount = s.Count(c => c == 'A');
            if (s.Contains("LLL") || aCount >= 2)
                return false;
            return true;
        }
    }
    

Log in to reply
 

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