Solution in Java Using Regular Expressions for Detect Capital problem


  • 0
    R
    class Solution {
        public boolean detectCapitalUse(String word) {
            if(word.matches("[A-Z]*")){
                return true;
            }
            else if(word.matches("^[A-Z][a-z]*")){
                return true;
            }
            else if(word.matches("[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.