-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathver3_LongNonRepSubSequence.py
More file actions
58 lines (41 loc) · 1.37 KB
/
ver3_LongNonRepSubSequence.py
File metadata and controls
58 lines (41 loc) · 1.37 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 28 13:39:21 2023
least complicated version I could come up with so far
bug (does not affect results): the last char in string is included twice
@author: utpal
"""
class Solution(object):
def __init__(self, s):
self.strseq = s
def findLongestSubString(self, strseq):
lst = []
if len(strseq) == 0:
return -1
if len(strseq) == 1:
return 1
for index, val in enumerate(strseq):
inLst = []
inLst.append(val)
for i, char in enumerate(strseq[index+1:]):
if char in inLst:
lst.append(inLst)
break
else:
inLst.append(char)
if inLst not in lst:
lst.append(inLst)
if (index+1 == len(strseq)):
lst.append(list(strseq[-1]))
max_len = 0
for item in lst:
if len(item) > max_len:
max_len = len(item)
return max_len, lst
s = "bbbbbxcv"
#s = "abcabc"
#s = "pwwkec"
x = Solution(s)
max_len, new_lst = x.findLongestSubString(s)
print (f"Longest unique substring is: {max_len};\
\nAll combinations tried for max length are:\n {new_lst}")