-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMySolution.java
44 lines (38 loc) · 1017 Bytes
/
MySolution.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.*;
import java.util.*;
class GURU
{
public static void main(String args[]) throws IOException
{
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while (t > 0)
{
String A = sc.nextLine();
String B = sc.nextLine();
Solution ob = new Solution();
System.out.println(ob.repeatedStringMatch(A,B));
t--;
}
}
}
class Solution
{
static int repeatedStringMatch(String A, String B)
{
if ( A.indexOf(B) != -1 )
return 1;
StringBuilder aaa = new StringBuilder("");
StringBuilder bbb = new StringBuilder("");
int length = B.length()+A.length();
int repeated = 0;
while ( (aaa.indexOf(B) == -1) && (aaa.length() < length) )
{
aaa.append(A);
++repeated;
}
if ( aaa.indexOf(B) == -1 )
return -1;
return repeated;
}
}