O(1) Solution


  • 0
    L

    Using Regular Expression



    class Solution {

        public boolean detectCapitalUse(String word) {
             boolean f1 = word.matches("([a-z]*)");
             boolean f2 = word.matches("([A-Z])([a-z]*)");
             boolean f3 = word.matches("([A-Z]*)");        
             return f1 || f2 || f3;
        }
    

    }


Log in to reply
 

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