easy to understand java code


  • 0
    Y

    '''
    public int repeatedStringMatch(String A, String B) {
    int alen = A.length();
    int blen = B.length();
    int count = blen / alen;
    if(blen % alen != 0) count++;
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < count; i++){
    sb.append(A);
    }
    if(!sb.toString().contains(B)){
    sb.append(A);
    count++;
    if(!sb.toString().contains(B)) return -1;
    }
    return count;

    }
    

    ''''


Log in to reply
 

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