Super simple JS solution


  • 0
    D
    var repeatedStringMatch = function(A, B) {
        let result = Math.ceil(B.length / A.length)
        const [str1, str2] = [A.repeat(result), A.repeat(result + 1)]
        
        if (str1.includes(B)) return result
        if (str2.includes(B)) return result + 1
    
        return -1
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.