Count The Repetitions LeetCode solution in Python

1
class Solution:
2
def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int:
3
dp = []
4
for i in range(len(s2)):
5
start = i
6
cnt = 0
7
for j in range(len(s1)):
8
if s1[j] == s2[start]:
9
start += 1
10
if start == len(s2):
11
start = 0
12
cnt += 1
13
dp.append((start, cnt))
14
res = 0
15
next = 0
16
for _ in range(n1):
17
res += dp[next][1]
18
next = dp[next][0]
19
return res // n2

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0