给定一个由n个字符组成的字符串A和一个由m个字符组成的字符串B,编写一个函数,使得B是重复的A的子字符串,该函数将返回字符串A最少需重复的次数,
Question 1:
Given a string A consisting of n characters and a string B consisting of m characters, write a function that will return the number of times A must be stated such that B is a substring of the repeated A. If B can never be a substring, return -1.
Example:
A = ‘abcd’
B = ‘cdabcdab’
The function should return 3 because after stating A 3 times, getting ‘abcdabcdabcd’, B is now a substring of A.
You can assume that n and m are integers in the range [1, 1000].
给定包含N个字母的string A和包含M个字母的string B,返回使得B成为其子字符串A需> 要重复自己的最少次数。如果无论A重复自己多少次B都无法成为其子字符串,返回-1。
如下面例子所示:
A = “abcd”
B = “cdabcdab”
这种情况下该函数需要返回3,因为A重复3次后成为`”abcdabcdabcd”,此时B是该字符串的子串。
本题假定:
N是[1…1000]内的整数。
M是[1…1000]内的整数。
public static int minimumNumberRepeat(String A,String B){
if(A==null || A.length() == 0){
return -1;
}
if(A.length()>B.length()){
for(int i = 0;i<2;i++){
String curr = new String(new char[i+1]).replaceAll("\0",A