3-line JavaScript O(mn) solution


  • 0
    const repeatedStringMatch = (A, B) => {
        const count = Math.ceil(B.length / A.length)
        const str = A.repeat(count)
        return str.includes(B) ? count : (str + A).includes(B) ? count + 1 : -1 
    };
    

Log in to reply
 

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