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 重复叠加字符串匹配
最新推荐文章于 2024-07-19 22:53:00 发布