Use Regex


  • 0
    Y
      public bool DetectCapitalUse(string word)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(word, @"^[A-Z]+$"))
                    return true;
    
                if (System.Text.RegularExpressions.Regex.IsMatch(word, @"^[a-z]+$"))
                    return true;
    
                if (System.Text.RegularExpressions.Regex.IsMatch(word, @"^[A-Z]{1}[a-z]+$"))
                    return true;
    
                return false;
            }

Log in to reply
 

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