-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsol.py
61 lines (52 loc) · 1.48 KB
/
sol.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
import collections
class StrCnt:
def __init__(self, theStr):
self.chars = collections.Counter(theStr)
self.added = collections.Counter()
def add(self, char):
self.added[char] += 1
def remove(self, char):
if self.added[char] == 1:
del self.added[char]
return
self.added[char] -= 1
def isValid(self):
for char in self.chars:
if not self.added[char]:
return False
if self.added[char] < self.chars[char]:
return False
return True
class Solution:
def minWindow(self, s: str, t: str) -> str:
desired = StrCnt(t)
sx = 0
ex = 0
whoMoved = 0
minStr = ''
minStrSize = float('inf')
while sx <= ex:
isValid = desired.isValid()
if isValid:
curValidStr = s[sx:ex]
if len(curValidStr) < minStrSize:
minStrSize = len(curValidStr)
minStr = curValidStr
# print(desired.added)
desired.remove(s[sx])
sx += 1
else:
if ex >= len(s):
break
desired.add(s[ex])
ex += 1
return minStr
n = [2,3,2]
s = Solution()
# res = s.minWindow("ADOBECODEBANC", "ABC")
# res = s.minWindow("ABCBA", "AB")
a = 1,2,3
print(a[0])
# print(len(collections.Counter("AAAABBC")))
# print(res)
# print(n[1:])