Advertisement
Josif_tepe

Untitled

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