Check If String Is Transformable With Substring Sort Operations LeetCode solution in Python

1
from collections import defaultdict
2

3

4
class Solution:
5
def isTransformable(self, s: str, t: str) -> bool:
6
index = defaultdict(list)
7
for i, c in enumerate(s):
8
index[c].append(i)
9
curpos = defaultdict(int)
10
for c in t:
11
if curpos[c] == len(index[c]):
12
return False
13
for i in range(int(c)):
14
i = str(i)
15
if (
16
curpos[i] < len(index[i])
17
and index[i][curpos[i]] < index[c][curpos[c]]
18
):
19
return False
20
curpos[c] += 1
21
return True

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0