Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 1.09 KB

풀이_LC520.md

File metadata and controls

35 lines (25 loc) · 1.09 KB

😛 520. Detect Capital

  • Date : 2021.10.03(일)
  • Time : 10분

Problem

  • We define the usage of capitals in a word to be right when one of the following cases holds:
    • All letters in this word are capitals, like "USA".
    • All letters in this word are not capitals, like "leetcode".
    • Only the first letter in this word is capital, like "Google".
  • Given a string word, return true if the usage of capitals in it is right.

Constraints

  • 1 <= num <= 10^8

Example

  • Input: word = "FlaG"
  • Output: false

풀이

    def detectCapitalUse(self, word: str) -> bool:
        if word.lower() == word or word.upper() == word or word.title() == word:
            return True
        else:
            return False
    
        

: 모든 문자가 대문자 이거나 첫문자만 대문자 이거나 모든 문자가 소문자일 때만 true 이다. lower()을 쓰면 모두 소문자로 변환된다. upper()을 쓰면 반대로 모두 대문자로 변환된다. title()은 각 단어의 첫글자는 대문자로, 나머지는 소문자로 변환하는 함수이다.