多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1. `For example, with A = "abcd" and B = "cdabcdab".` Return 3, because by repeating A three times (“abcdabcdabcd”), B is a substring of it; and B is not a substring of A repeated two times ("abcdabcd"). ``` /** * @param {string} A * @param {string} B * @return {number} */ var repeatedStringMatch = function(A, B) { var n = B.length/A.length; var str = ""; for(var i = 1; i<n+5; i++){ str += A; if(str.indexOf(B)>=0){ return i; } } return -1; }; ```