Java - 188 ms


  • 0
    S

    class Solution {
    public int repeatedStringMatch(String A, String B) {
    if(A == null && B == null || (A.contains(B)))
    return 1;

            StringBuilder newS = new StringBuilder();
            newS = newS.append(A);
            int count =1;
           // if B size large than +1
           // if A size larger than +2
          // to make sure no matter A length longer or B the while do once
          // I use 2 for all the cases.
            while((B.length() / A.length())+2 >= count) {
                if(newS.toString().contains(B)) 
                    return count;
                    newS = newS.append(A);
                    count++;
            }
      
        return -1;
            
        }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.