Leetcode Repeated Substring Pattern
2016-12-31 04:32
453 查看
题意:给出一个字符串,判断其是否由一个子串重复多次构成。
思路:枚举字串长度。
class Solution {
public:
bool repeatedSubstringPattern(string str) {
string s1;
string s2;
for(int i = 1; i < str.length(); i ++) {
if(str.length() % i) continue;
s1 = str.substr(0, i);
bool isR = true;
for(int j = i; j < str.length(); j += i) {
s2 = str.substr(j, i);
if(s1 != s2){
isR = false;
break;
}
}
if(isR) return true;
}
return false;
}
};
思路:枚举字串长度。
class Solution {
public:
bool repeatedSubstringPattern(string str) {
string s1;
string s2;
for(int i = 1; i < str.length(); i ++) {
if(str.length() % i) continue;
s1 = str.substr(0, i);
bool isR = true;
for(int j = i; j < str.length(); j += i) {
s2 = str.substr(j, i);
if(s1 != s2){
isR = false;
break;
}
}
if(isR) return true;
}
return false;
}
};
相关文章推荐
- leetcode-459-Repeated Substring Pattern
- LeetCode Repeated Substring Pattern
- LeetCode459——Repeated Substring Pattern
- Leetcode: Repeated Substring Pattern
- 【LeetCode 459】 Repeated Substring Pattern
- leetcode oj java Repeated Substring Pattern
- leetcode[Repeated Substring Pattern]//待整理多种解法
- [LeetCode]Repeated Substring Pattern(Java)
- 【LeetCode】Repeated Substring Pattern 解题报告
- LEETCODE--Repeated Substring Pattern
- Leetcode 459 Repeated Substring Pattern
- [LeetCode] Repeated Substring Pattern 重复子字符串模式
- LeetCode : Repeated Substring Pattern
- [LeetCode] Longest substring without repeated characters
- Repeated Substring Pattern
- String-459-Repeated Substring Pattern
- 459. Repeated Substring Pattern*
- Repeated Substring Pattern
- Repeated Substring Pattern
- Repeated Substring Pattern