Skip to content

Commit 2128daa

Browse files
committed
repeated substring patterns
1 parent df800e3 commit 2128daa

File tree

3 files changed

+70
-49
lines changed

3 files changed

+70
-49
lines changed

.idea/workspace.xml

Lines changed: 42 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@ codes may not be optimized
402402

403403
1. [Path Sum III](https://leetcode.com/problems/path-sum-iii/description/)
404404
1. [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements/description/)
405+
1. [Repeated Substring Patterns](https://leetcode.com/problems/repeated-substring-pattern/description/)
405406

406407
### Day 19 - Medium
407408

408409
1. [Path Sum II](https://leetcode.com/problems/path-sum-ii/description/)
409410
1. [Minimum Moves to Equal Array Elements II](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/description/)
411+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.chen0040.leetcode.day19.easy;
2+
3+
4+
/**
5+
* Created by xschen on 14/8/2017.
6+
*
7+
* link: https://leetcode.com/problems/repeated-substring-pattern/description/
8+
*/
9+
public class RepeatedSubstringPatterns {
10+
public class Solution {
11+
public boolean repeatedSubstringPattern(String s) {
12+
for(int i = s.length() / 2; i >= 1;--i) {
13+
if(s.length() % i == 0) {
14+
int count = s.length() / i;
15+
String comp = s.substring(0, i);
16+
StringBuilder sb = new StringBuilder();
17+
for(int j = 0; j < count; ++j) {
18+
sb.append(comp);
19+
}
20+
if(sb.toString().equals(s)) return true;
21+
}
22+
}
23+
return false;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)