-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon2.py
52 lines (48 loc) · 1.37 KB
/
amazon2.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(S):
resp = -1
# digitsIndexList = []
# upperCaseIndexList = []
# for i in range(len(S)):
# if S[i].isupper():
# upperCaseIndexList.append(i)
# if S[i].isdigit():
# digitsIndexList.append(i)
# i=-1
# for end in digitsIndexList:
# valid = False
# for index in upperCaseIndexList:
# if index >i and index < end:
# valid = True
# break
# if valid == True:
# resp = max(resp, end-i+1)
# i = end
# if len(digitsIndexList) > 0:
# i = digitsIndexList[-1]
# end = len(S)-1
# valid = False
# for index in upperCaseIndexList:
# if index >i and index < end:
# valid = True
# break
# if valid == True:
# resp = max(resp, end-i+1)
# return resp
current = 0
valid = False
for letter in S:
if letter.isupper():
valid = True
if not letter.isdigit():
current+=1
else:
if valid == True:
resp = max(resp, current)
current = 0
valid = False
if valid == True:
resp = max(resp, current)
return resp
print solution("a0Bs")