scala version


  • 0
    M
      def detectCapitalUse(word: String): Boolean = {
        for (char <- word) {
          if (char < 'a' && word.indexOf(char) != 0 && word.dropWhile(_ == char).exists(x => x > 'a')) return false
        }
        true
      }
    
      def detectCapitalUseReg(word: String): Boolean = {
        word.matches("[A-Z]*|[A-Z]?[a-z]*")
      }
    

Log in to reply
 

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