-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm2486 Daily v1.py
37 lines (28 loc) · 1.05 KB
/
m2486 Daily v1.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
# bottom 5% for both memory and runtime damn
class Solution:
def appendCharacters(self, s: str, t: str) -> int:
if s == t:
return 0
# Getting the indicies of each value and storing them for O(1) lookups
sSpots = {}
for i in range(len(s)) :
temp = sSpots.get(s[i], [])
temp.append(i)
sSpots[s[i]] = temp
currentSpotT: int = 0
currentSpotS = -1
# Go until we can't find a index to use that's farther than our current spot
while currentSpotT < len(t) :
temp = sSpots.get(t[currentSpotT], [])
if len(temp) == 0 :
break
while True :
indCheck = temp.pop(0)
if indCheck > currentSpotS :
currentSpotS = indCheck
sSpots[t[currentSpotT]] = temp
break
if len(temp) == 0 :
return len(t) - currentSpotT
currentSpotT += 1
return len(t) - currentSpotT