Repeated String Match (Leetcode 686)

Problem Link: https://leetcode.com/problems/repeated-string-match/

class Solution:
    def repeatedStringMatch(self, a: str, b: str) -> int:
        
        temp=''
        count=0
        # Append to the string until
        # the length of temp > b
        while(len(temp)<len(b)):
            temp=temp+a
            count+=1
        
        if(b in temp):
            return count
        if(b in (temp+a)):
            return count+1
        
        return -1

Last updated