Easy to understand Java Solution


  • 0
    E
    public class Solution {
        public boolean detectCapitalUse(String word) {
            int flag1=0,flag2=0,flag3=0;
            for(int i=0;i<word.length();i++){
                if(word.charAt(i)>=65 && word.charAt(i)<=91){
                    if(i==0){
                        flag1=1;
                    }
                    else{
                        flag2=1;
                    }
                }
                else{
                    flag3=1;
                    if(flag2==1){
                        return false;
                    }
                }
            }
            if(flag3==1 && flag2==1){
                return false;
            }
            return true;
        }
    }
    

Log in to reply
 

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