Skip to content

Commit c2cee35

Browse files
authored
Create longest-substring-of-all-vowels-in-order.py
1 parent 7f75cbb commit c2cee35

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def longestBeautifulSubstring(self, word):
6+
"""
7+
:type word: str
8+
:rtype: int
9+
"""
10+
result = 0
11+
l = cnt = 1
12+
for i in xrange(len(word)-1):
13+
if word[i] > word[i+1]:
14+
l = cnt = 1
15+
else:
16+
l += 1
17+
cnt += int(word[i] < word[i+1])
18+
if cnt == 5:
19+
result = max(result, l)
20+
return result

0 commit comments

Comments
 (0)