Skip to content

Commit e299914

Browse files
author
Wentian Li
committed
fd
1 parent 5629e93 commit e299914

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

.DS_Store

-2 KB
Binary file not shown.

leetcode/solution/src/RepeatedSubstringPattern.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ public class RepeatedSubstringPattern {
55
*/
66
public boolean repeatedSubstringPattern(String str) {
77
int l = str.length();
8+
boolean flag = true;
89
for (int i = l / 2; i >= 1; i--) {
910
if (l % i == 0) {
1011
int m = l / i;
12+
if (m % 2 == 0 && !flag) {
13+
continue;
14+
}
1115
String subS = str.substring(0, i);
1216
StringBuilder sb = new StringBuilder();
1317
for (int j = 0; j < m; j++) {
1418
sb.append(subS);
1519
}
1620
if (sb.toString().equals(str)) return true;
21+
flag = false;
1722
}
1823
}
1924
return false;

0 commit comments

Comments
 (0)