Skip to content

Commit f412550

Browse files
authored
Create 459.cpp
1 parent 2f1de8d commit f412550

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

leetcode/cpp/string/459.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution {
2+
public:
3+
bool repeatedSubstringPattern(string s) {
4+
string t="";
5+
if(s.size()==1)
6+
{
7+
return false;
8+
}
9+
int n=s.size();
10+
for(int i=0;i<s.size()/2;i++)
11+
{
12+
t+=s[i];
13+
// cout<<t<<endl;
14+
int x=t.size();
15+
if(n%x==0)
16+
{
17+
string res;
18+
for(int j=0;j<n/x;j++)
19+
{
20+
res+=t;
21+
}
22+
if(res==s)
23+
{
24+
// cout<<res;
25+
return true;
26+
27+
}
28+
}
29+
30+
}
31+
return false;
32+
}
33+
};

0 commit comments

Comments
 (0)