C# beats 79%


  • 0
    public bool DetectCapitalUse(string word) {
            
            bool allCap = true;
            for(int i = 0;i<word.Length;i++)
            {
                if(word[i].ToString() != word[i].ToString().ToUpper())
                {
                    allCap= false;
                }
            }
            
            // all lower or first cap
            bool allLowerOrFirstCap = true;
            for(int i = 1;i<word.Length;i++)
            {
                if(word[i].ToString() != word[i].ToString().ToLower())
                {
                    allLowerOrFirstCap= false;
                }
            }
            
            return allCap || allLowerOrFirstCap;
        }
    

Log in to reply
 

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