Skip to content

520. Detect Capital

https://leetcode.com/problems/detect-capital/

js
/**
 * @param {string} word
 * @return {boolean}
 */
var detectCapitalUse = function(word) {
  return word.toUpperCase() === word || word.slice(1).toLowerCase() === word.slice(1)
}
py
class Solution:

    def detectCapitalUse(self, word):
        """
        :type word: str
        :rtype: bool
        """
        return word.upper() == word or word[1:].lower() == word[1:]