您的位置:首页 > 其它

LeetCode Weekly Contest 52 Repeated String Match(string)

2017-10-01 11:46 435 查看
题目:https://leetcode.com/contest/leetcode-weekly-contest-52/problems/repeated-string-match/

题意:让你求最少重复A多少次,才能在使得B是A的子串;如果不能,输出-1

思路:我竟然懵逼的写了kmp,还wa了几次……

直接string就行

代码:

class Solution {
public:
int repeatedStringMatch(string A, string B) {
int cnt = 1;
string str = A;
while(str.length() < B.length())
str += A,cnt++;
if(str.find(B) != -1)
return cnt;
str += A,cnt++;
if(str.find(B) != -1)
return cnt;
return -1;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: