-
Notifications
You must be signed in to change notification settings - Fork 0
/
substring.py
63 lines (53 loc) · 1.48 KB
/
substring.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
53
54
55
56
57
58
59
60
61
62
63
"""
Get Repeated Substring
"""
string = "clementisacap"
def getRepeatedSubString(string):
res = []
length = len(string)
# def isPalindrome(palin):
# left, right = 0, len(palin) - 1
# while left < right:
# if palin[left] != palin[right]:
# return False
# left += 1
# right -= 1
# return True
#
#
largest = ''
for row in range(length):
for col in range(row + 1, length + 1):
unique = string[row:col]
lst = []
for un in unique:
if un not in lst:
lst.append(un)
else:
break
if len(unique) == len(lst) and len(largest) < len(lst):
largest = unique
return largest
# res.append(string[row:col])
# for row in range(length):
# for col in range(row + 1, length + 1):
# palin = string[row:col]
# # if isPalindrome(palin) and len(palin) > 1:
# # res.append(palin)
# left, right = 0, 0
# while right <= len(string):
# res.append(string[left:right])
# right += 1
#
# left, right = 0, length - 1
# while left < right:
# res.append(string[left:right])
# left += 1
#
# left, right = 0, length
# while left < right:
# res.append(string[left:right])
# left += 1
# right -= 1
return res
print(getRepeatedSubString(string))