파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2023. 1. 2. 23:45

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

 

Detect Capital - LeetCode

Detect Capital - 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

leetcode.com

매우 간단스한 문제.
문자열을 조건대로 변환해서 비교하면 끝!

class Solution:
    def detectCapitalUse(self, word: str) -> bool:
        if word.upper() == word:
            return True
        if word.lower() == word:
            return True
        if word.upper()[:1] + word.lower()[1:] == word:
            return True
        return False
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2023.01.04
Today's Challenge  (0) 2023.01.03
Today's Challenge  (0) 2023.01.01
Today's Challenge  (0) 2022.12.31
Today's Challenge  (0) 2022.12.30
Comments