[686. Repeated String Match]My C++ Solution


  • 1
    class Solution {
    public:
        int repeatedStringMatch(string A, string B) {
            int repeatedCount = 1;
            string repeatedString = A;
            
            // while B is not found in A
            while(A.find(B) == std::string::npos && A.length() <= 10000)
            {
                repeatedCount++;
                A += repeatedString;
            }
    
            return (A.length() > 10000) ? -1 : (repeatedCount);
        }
    };
    

Log in to reply
 

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