BiruLyu
10/1/2017 - 3:58 AM

686. Repeated String Match.java

class Solution {
    public int repeatedStringMatch(String A, String B) {
        StringBuilder sb = new StringBuilder();
        int lenB = B.length();
        int cnt = 0;
        while (sb.length() < lenB) {
            sb.append(A);
            cnt++;
        }
        if (sb.toString().indexOf(B) >= 0) {
            return cnt;
        }
        sb.append(A);
        cnt++;
        if (sb.toString().indexOf(B) >= 0) {
            return cnt;
        }
        return -1;
    }
}