833. Find And Replace in String (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution:
    def findReplaceString(self, s: str, indices: List[int], sources: List[str], targets: List[str]) -> str:
        arr = sorted(zip(indices, sources, targets))
        n = len(arr)
        result = ""
        i = 0
        for j in range(n):
            a, b, c = arr[j]
            result += s[i : a]
            i = a
            if s[a : a + len(b)] == b:
                result += c
                i += len(b)
        result += s[i : ]
        return result