-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday23.java
More file actions
26 lines (19 loc) · 777 Bytes
/
day23.java
File metadata and controls
26 lines (19 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//ques1:686. Repeated String Match
//link:https://leetcode.com/problems/repeated-string-match/description/
public class Solution {
public int repeatedStringMatch(String A, String B) {
if (A == null || B == null || A.length() == 0 || B.length() == 0) return -1;
StringBuilder newstr = new StringBuilder();
int repeatCount = (int) Math.ceil((double) B.length() / A.length()) ;
for (int i = 0; i < repeatCount; i++) {
newstr.append(A);
}
if (newstr.toString().contains(B)) {
return repeatCount;
} else if (newstr.append(A).toString().contains(B)) {
return repeatCount + 1;
} else {
return -1;
}
}
}