-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10_1.java
41 lines (32 loc) · 839 Bytes
/
day10_1.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
//Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
class Solution {
static int minRepeats(String A, String B) {
// code here
int ans =-1;
int a_len = A.length();
int b_len = B.length();
int i=1;
int min = a_len;
while(min<b_len)
{
i++;
min = a_len*i;
}
String str = "";
for(int j=0; j<i; j++)
{
str = str+A;
}
if(str.contains(B))
{
return i;
}
str = str+A;
if(str.contains(B))
{
return i+1;
}
return ans;
}
};
//question asked in google