-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay97.java
More file actions
28 lines (23 loc) · 697 Bytes
/
Day97.java
File metadata and controls
28 lines (23 loc) · 697 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
27
public class Day97 {
public static int minRepeats(String a, String b) {
int repeat = 1;
StringBuilder repeatedA = new StringBuilder(a);
while (repeatedA.length() < b.length()) {
repeatedA.append(a);
repeat++;
}
if (repeatedA.toString().contains(b)) {
return repeat;
} else {
return -1;
}
}
public static void main(String[] args) {
String a1 = "abcd";
String b1 = "cdabcdab";
System.out.println("Output 1: " + minRepeats(a1, b1));
String a2 = "a";
String b2 = "aa";
System.out.println("Output 2: " + minRepeats(a2, b2));
}
}