Golang | Leetcode Golang题解之第466题统计重复个数

题目:

题解:

func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) int {
	n := len(s2)
	cnt := make([]int, n)
	for i := 0; i < n; i++ {
        // 如果重新给一个s1 并且s2是从第i位开始匹配 那么s2可以走多少位(走完了就从头开始走
		p1, p2 := 0, i
		for p1 < len(s1) {
			if s1[p1] == s2[p2 % n] {
				p2++
			}
            p1++
		}
        // 统计如果是从s2的第i位开始走 给一个新的s1 s2能走多少位
		cnt[i] = p2 - i
	}
	index := 0
    // 直接模拟不断给s1 然后看s2能新走多少位
	for i := 0; i <n1; i++ {
		index += cnt[index % n]
	}
	return index / n / n2

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值