Leetcode 686 Solution

This article provides solution to leetcode question 686 (repeated-string-match)

https://leetcode.com/problems/repeated-string-match

Solution

class Solution {
public:
    int repeatedStringMatch(string A, string B) {
        string res;

        while (res.size() < B.size())
            res += A;

        if (res.find(B) != string::npos)
            return res.size() / A.size();

        res += A;

        return res.find(B) != string::npos ? res.size() / A.size() : -1;
    }
};