Skip to content

Commit b1a967c

Browse files
committed
solution for lc686
1 parent 353f795 commit b1a967c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

String.md

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ No.|Title|Difficulty|Solved|Date
33
--|:--:|--:|--:|--:|
44
58|[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)|Easy|yes|2019-01-08
55
680|[Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii/)|Easy|yes|2019-1-14
6+
686|[Repeated String Match](https://leetcode.com/problems/repeated-string-match/)|Easy|yes|2019-1-14
67
696|[Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings/)|Easy|yes|2019-01-11
78
848|[Shifting Letters](https://leetcode.com/problems/shifting-letters/)|Medium|yes|2019-01-12
89
859|[Buddy Strings](https://leetcode.com/problems/buddy-strings/)|Easy|yes|2019-01-09
@@ -47,6 +48,10 @@ public boolean validPalindrome(String s) {
4748
}
4849
```
4950

51+
686. [Repeated String Match](https://leetcode.com/problems/repeated-string-match/)
52+
53+
字符串问题。计算字符串A叠加多少次之后,可以包含字符串B。注意退出条件即可。
54+
5055
696. [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings/)
5156

5257
对于给定的字符串,可以形成 m * 1 + n * 0 + m1 * 1 + n1 * n这种形式。

src/main/java/easy/lc686.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//https://leetcode.com/problems/repeated-string-match/
2+
//686. Repeated String Match
3+
class Solution {
4+
public int repeatedStringMatch(String A, String B) {
5+
StringBuilder sb = new StringBuilder(A);
6+
int count = 1;
7+
while (true) {
8+
if (sb.length() < B.length()) {
9+
sb.append(A);
10+
count++;
11+
} else {
12+
if (sb.indexOf(B) >= 0) {
13+
return count;
14+
} else {
15+
sb.append(A);
16+
count++;
17+
if (sb.indexOf(B) >= 0) return count;
18+
return -1;
19+
}
20+
}
21+
}
22+
// return -1;
23+
}
24+
}

0 commit comments

Comments
 (0)