Advertisement
Josif_tepe

Untitled

Dec 14th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int repeatedStringMatch(string a, string b) {
  4.         int n = a.size(), m = b.size();
  5.         int rep = m / n;
  6.         string s = "";
  7.         for(int i = 0; i < rep; i++) {
  8.             s += a;
  9.         }
  10.         for(int i = 0; i < 5; i++)  {
  11.             if(s.find(b) != string::npos) {
  12.                 return rep + i;
  13.             }
  14.             s += a;
  15.            
  16.         }
  17.         return -1;
  18.     }
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement