【字符串】686. 重复叠加字符串匹配
题目:

解答:
重复累加,当B.size()+temp.size()<n*A.size()时仍不是子串时,就可以判断false了!
原理是因为继续累加temp得到的知识重复的结果,没有意义。
1 class Solution { 2 public: 3 int repeatedStringMatch(string A, string B) 4 { 5 int count=1; 6 string temp=A; 7 while(1) 8 { 9 if(A.find(B)!=A.npos) 10 break; 11 else if(A.size()>B.size()+temp.size()) 12 return -1; 13 { 14 A+=temp; 15 ++count; 16 } 17 } 18 return count; 19 } 20 };

浙公网安备 33010602011771号