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就行
代码:
题意:让你求最少重复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; } };
相关文章推荐
- LeetCode Weekly Contest 13-Matchsticks to Square【中】
- leetcode 686 Repeated String Match
- [LeetCode] Repeated String Match 重复字符串匹配
- Leetcode挑战题——Repeated String Match
- LeetCode -- Google -- Interview Process. 1. Repeated String Match(java)
- LeetCode Weekly Contest 23 之 536.Construct Binary Tree from String
- Leetcode | Repeated String Match
- LeetCode Weekly Contest 64 - 752. Open the Lock【BFS + string】
- leetcode 686 Repeated String Match
- LeetCode Repeated String Match
- LeetCode Weekly Contest 52 Longest Univalue Path(链表dfs)
- LeetCode Weekly Contest 40(1) - Average of Levels in Binary Tree
- LeetCode Weekly Contest 40解题思路
- LeetCode Weekly Contest 31解题思路
- LeetCode Weekly Contest 26解题思路
- LeetCode Weekly Contest 24 之 538.Convert BST to Greater Tree
- LeetCode Weekly Contest 24 之 542.01 Matrix
- String-686-Repeated String Match
- LeetCode Weekly Contest 45解题思路
- LeetCode Weekly Contest 41解题思路