Skip to content

Commit f6b529a

Browse files
authored
Create 459.Repeated-Substring-Pattern_v1.cpp
1 parent 2038448 commit f6b529a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
bool repeatedSubstringPattern(string s)
4+
{
5+
for (int i=s.size()/2; i>=1; i--)
6+
{
7+
if (s.size()%i!=0) continue;
8+
9+
int flag=1;
10+
string t = s.substr(0,i);
11+
int j=i;
12+
while (j<s.size())
13+
{
14+
if (t!=s.substr(j,i))
15+
{
16+
flag=0;
17+
break;
18+
}
19+
j+=i;
20+
}
21+
22+
if (flag==1) return true;
23+
}
24+
25+
return false;
26+
27+
}
28+
};

0 commit comments

Comments
 (0)