Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- ubuntu
- 백준
- Baekjoon
- 맥북
- Docker
- leetcode
- 금융문자분석경진대회
- gs25
- github
- SW Expert Academy
- PYTHON
- 편스토랑
- programmers
- Real or Not? NLP with Disaster Tweets
- 편스토랑 우승상품
- 자연어처리
- 코로나19
- 프로그래머스
- dacon
- 우분투
- 프로그래머스 파이썬
- hackerrank
- 파이썬
- Kaggle
- ChatGPT
- Git
- AI 경진대회
- 데이콘
- 캐치카페
- 더현대서울 맛집
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 520. Detect Capital (Python) 본문
728x90
반응형
Given a word, you need to judge whether the usage of capitals in it is right or not.
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".
Otherwise, we define that this word doesn't use capitals in a right way.
Example 1:
Input: "USA"
Output: True
Example 2:
Input: "FlaG"
Output: False
Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
Solution
class Solution:
def detectCapitalUse(self, word: str) -> bool:
upper_word = word.upper()
lower_word = word.lower()
answer = False
if upper_word == word or lower_word == word:
answer = True
if len(word) > 0 and (word[0] == upper_word[0] and word[1:] == lower_word[1:]):
answer = True
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 717. 1-bit and 2-bit Characters (Python) (0) | 2021.01.17 |
---|---|
[leetCode] 908. Smallest Range I (Python) (0) | 2021.01.16 |
[leetCode] 237. Delete Node in a Linked List (Python) (0) | 2021.01.14 |
[leetCode] 492. Construct the Rectangle (Python) (0) | 2021.01.13 |
[leetCode] 461. Hamming Distance (Python) (0) | 2021.01.12 |
Comments