simple, easy to understand


  • 0
    V
    public int allLower = 0; public int allCapital = 1; public int mixed = 2;
        public bool DetectCapitalUse(string word) {
            if(word == null || word.Length == 0 || word.Length == 1) return true;
            var rest = letters(word.Substring(1, word.Length -1));
            if(char.IsLower(word[0])) return rest == 0;
            return rest == 0 || rest == 1;
        }
        
        public int letters(string str){
            bool lower = false; bool upper = false; bool mixed = false;
            for(int i=0;i<str.Length;i++){
                if(char.IsLower(str[i])) lower=true;
                else upper=true;
                if(lower && upper) return 2;
            }
            
            if(lower && !upper)  return 0;
            return 1;
        }
    

Log in to reply
 

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