Find And Replace in String LeetCode solution in Python

1
class Solution:
2
def findReplaceString(
3
self, s: str, indices: List[int], sources: List[str], targets: List[str]
4
) -> str:
5

6
inputs = list(zip(indices, sources, targets))
7
inputs.sort(key=lambda x: x[0])
8

9
offset = 0
10
for idx, src, tgt in inputs:
11
idx += offset
12
if s[idx : idx + len(src)] != src:
13
print("hi")
14
print(idx)
15
continue
16

17
offset += len(tgt) - len(src)
18
s = s[:idx] + tgt + s[idx + len(src) :]
19

20
return s

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0