Skip to content

Commit 8b1899d

Browse files
committed
fd
1 parent 0a1368b commit 8b1899d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
|449|[Serialize and Deserialize BST](https://leetcode.com/problems/serialize-and-deserialize-bst)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SerializeAndDeserializeBST.java)|90|#297一样|
357357
|450|[Delete Node in a BST](https://leetcode.com/problems/delete-node-in-a-bst/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/DeleteNodeInBST.java)|60|这题非常经典,值得多做十遍|
358358
|451|[Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SortCharactersByFrequency.java)|||
359+
|459|[Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RepeatedSubstringPattern.java)|||
359360
|477|[Total Hamming Distance](https://leetcode.com/problems/total-hamming-distance/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/TotalHammingDistance.java)||
360361
|480|[Sliding Window Median](https://leetcode.com/problems/sliding-window-median/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SlidingWindowMedian.java)|70||
361362
|482|[License Key Formatting](https://leetcode.com/problems/license-key-formatting/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/LicenseKeyFormatting.java)|90||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.inuker.solution;
2+
3+
/**
4+
* Created by liwentian on 2017/12/9.
5+
*/
6+
7+
public class RepeatedSubstringPattern {
8+
9+
/**
10+
* 先从重复两次开始试,再试重复3次,一直到重复1次
11+
*/
12+
public boolean repeatedSubstringPattern(String str) {
13+
int l = str.length();
14+
for (int i = l / 2; i >= 1; i--) {
15+
if (l % i == 0) {
16+
int m = l / i;
17+
String subS = str.substring(0, i);
18+
StringBuilder sb = new StringBuilder();
19+
for (int j = 0; j < m; j++) {
20+
sb.append(subS);
21+
}
22+
if (sb.toString().equals(str)) return true;
23+
}
24+
}
25+
return false;
26+
}
27+
}

0 commit comments

Comments
 (0)