import math
class Solution:
def repeatedStringMatch(self, a: str, b: str) -> int:
# 处理叠字的情况
Set_a, Set_b = set(a), set(b)
if Set_a & Set_b != Set_b:
return -1
# 下面就是正常逻辑的操作了
cnt_a = math.ceil(len(b) / len(a))
if b in a * cnt_a:
return cnt_a
elif b in a * (cnt_a + 1):
return cnt_a + 1
else:
return -1
LeetCode 686 重复叠加字符串匹配
字符串匹配算法详解
最新推荐文章于 2025-12-10 14:25:37 发布
523

被折叠的 条评论
为什么被折叠?



