Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 840 Bytes

936.-stamping-the-sequence.md

File metadata and controls

36 lines (26 loc) · 840 Bytes

936. Stamping The Sequence

class Solution:
    def movesToStamp(self, s: str, t: str) -> List[int]:
        
        
        n = len(s)
        m = len(t)
        t = list(t)
        s = list(s)
        
        res = []
        def check(i):
            changed = False
            for j in range(n):
                if t[i + j] == "*": continue
                if t[i + j] != s[j]: return False
                changed = True
                
            if changed:
                t[i:i + n] = ["*"] * n
                res.append(i)
            return changed
        
        changed = True
        while changed:
            changed = False
            for i in range(m - n + 1):
                changed |= check(i)
                
        return res[::-1] if t == ['*'] * m else []