-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathq0520.py
More file actions
26 lines (23 loc) · 740 Bytes
/
q0520.py
File metadata and controls
26 lines (23 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python3
from typing import List
class Solution:
def detectCapitalUse(self, word: str) -> bool:
length = len(word)
if length <= 1:
return True
isAllCapital = True
isAllNotCapital = True
for i in range(1, length):
char = word[i]
if "A" <= char <= "Z":
isAllNotCapital = False
else:
isAllCapital = False
if not isAllCapital and not isAllNotCapital:
return False
if "A" <= word[0] <= "Z" and (isAllCapital or isAllNotCapital):
return True
elif "a" <= word[0] <= "z" and isAllNotCapital:
return True
else:
return False