File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ No.|Title|Difficulty|Solved|Date
3
3
--|:--:|--:|--:|--:|
4
4
58|[ Length of Last Word] ( https://leetcode.com/problems/length-of-last-word/ ) |Easy|yes|2019-01-08
5
5
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
6
7
696|[ Count Binary Substrings] ( https://leetcode.com/problems/count-binary-substrings/ ) |Easy|yes|2019-01-11
7
8
848|[ Shifting Letters] ( https://leetcode.com/problems/shifting-letters/ ) |Medium|yes|2019-01-12
8
9
859|[ Buddy Strings] ( https://leetcode.com/problems/buddy-strings/ ) |Easy|yes|2019-01-09
@@ -47,6 +48,10 @@ public boolean validPalindrome(String s) {
47
48
}
48
49
```
49
50
51
+ 686 . [ Repeated String Match] ( https://leetcode.com/problems/repeated-string-match/ )
52
+
53
+ 字符串问题。计算字符串A叠加多少次之后,可以包含字符串B。注意退出条件即可。
54
+
50
55
696 . [ Count Binary Substrings] ( https://leetcode.com/problems/count-binary-substrings/ )
51
56
52
57
对于给定的字符串,可以形成 m * 1 + n * 0 + m1 * 1 + n1 * n这种形式。
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments