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.
Example 1:
Input: word = "USA"
Output: true
Example 2:
Input: word = "FlaG"
Output: false
Constraints:
- 1 <= word.length <= 100
- word consists of lowercase and uppercase English letters.
#https://leetcode.com/problems/detect-capital/description/
'''
1. 아이디어 :
대문자로 변환한 문자열과 비교하면 된다.
2. 시간복잡도 :
O(1)
3. 자료구조 :
문자열
'''
class Solution:
def detectCapitalUse(self, word: str) -> bool:
s1=word.upper()
s2=word.lower()
s3=word.capitalize()
return word==s1 or word==s2 or word==s3
'알고리즘 문제 > Leetcode' 카테고리의 다른 글
1200. Minimum Absolute Difference (0) | 2023.03.23 |
---|---|
733. Flood Fill (0) | 2023.03.23 |
207. Course Schedule (0) | 2023.03.19 |
129. Sum Root to Leaf Numbers (0) | 2023.03.16 |
113. Path Sum II (0) | 2023.03.16 |