Detect Capital LeetCode solution in Python

1
class Solution:
2
def detectCapitalUse(self, word: str) -> bool:
3
l = len(word)
4
if l == 1:
5
return True
6
if word[0] == word[0].lower() and word[1] == word[1].upper():
7
return False
8

9
u = False
10
if word[0] == word[0].upper():
11
if word[1] == word[1].upper():
12
u = True
13

14
for i in word[2:]:
15
if i == i.upper() and u == False:
16
return False
17
elif i == i.lower() and u == True:
18
return False
19
return True

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0