686. Repeated String Match判断字符串重复几次可以包含另外一个

public static int repeatedStringMatch(String A, String B) {
        //判断字符串a重复几次可以包含另外一个字符串b,就是不断叠加字符串a直到长度大于等于b,叠加一次计数+1
        //看现在的字符串是否包含b,包含就返回,不会包含就再叠加一次,因为可能有半截的在后边,再判断,再没有就返回-1
        int count = 0;
        StringBuilder sb = new StringBuilder();
        while (sb.length() < B.length()) {
            sb.append(A);
            count++;
        }
        if(sb.toString().contains(B)) return count;
        if(sb.append(A).toString().contains(B)) return ++count;
        return -1;
    }
原文地址:https://www.cnblogs.com/stAr-1/p/7795528.html