bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 686. Repeated String Match

686. Repeated String Match

Leetcode Solutions

Brute Force Approach

  1. Initialize a counter count to 1 and a StringBuilder with string a.
  2. Check if b is already a substring of a. If yes, return count.
  3. While the length of the StringBuilder is less than the length of b, append a to it and increment count.
  4. After each append, check if b is a substring of the StringBuilder. If yes, return count.
  5. If the length of the StringBuilder exceeds the length of b plus the length of a and b is still not a substring, return -1.
UML Thumbnail

Rabin-Karp Algorithm Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...