微信小程序选项卡功能开发步骤与方法全解析
686
2022-10-24
686. Repeated String Match
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”).
Note: The length of A and B will be between 1 and 10000.
class Solution { public int repeatedStringMatch(String A, String B) { String t = A ; for(int i = 1 ; i <= B.length()/A.length()+2 ; i++){ if (t.indexOf(B) != -1) return i ; else t += A
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~