-
Notifications
You must be signed in to change notification settings - Fork 0
/
Detect Capital.py
35 lines (28 loc) · 1.13 KB
/
Detect Capital.py
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
32
33
34
35
#Noob code:
#check if s[0] and s[1] is capital then rest must be capital.
#if s[0] is capital then rest are small(lowercase)
#if s[0] is small then rest character must be small.
def detectCapital(s):
n = len(s)
if len(s)==1:
return True
#if s[0] is uppercase
if 65 <= ord(s[0]) <=90:
#if s[1] is also upper case then no lowercase should be present.(ex: USA)
if 65 <= ord(s[1]) <=90:
for i in range(2,n):
#No lowercase character
if 97<= ord(s[i]) <=122:
return False
#if s[0] is upper case then No upper case is allowed, all must be lowercase (ex:Google)
else:
for i in range(1,n):
#No uppercase letters
if 65<= ord(s[i]) <=90:
return False
#all lowercase should be persent(ex:leetcode)
else:
for i in range(1,n):
if 65<= ord(s[i]) <=90:
return False
return True