Haskell solution


  • 0
    R
    import Data.List
    import Data.Char
    
    detectCapitalUse :: String -> Bool
    detectCapitalUse [] = error "Function accepts non-empty Strings only."
    detectCapitalUse s
      | onlyFirstUpper s = True
      | allUpper       s = True
      | allLower       s = True
      | otherwise        = False
      where
        onlyFirstUpper (x:xs) = isUpper x && allLower xs
        allUpper = all isUpper
        allLower = all isLower

Log in to reply
 

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