日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

466. 统计重复个数 golang[转]

發布時間:2023/11/30 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 466. 统计重复个数 golang[转] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載(mark)

https://blog.by24.cn/archives/leetcode-count-the-repetitions.html

func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) int {len1, len2 := len(s1), len(s2)index1, index2 := 0, 0 // 注意此處直接使用 Ra Rb 的下標,不取模if len1 == 0 || len2 == 0 || len1*n1 < len2*n2 {return 0}map1, map2 := make(map[int]int), make(map[int]int)ans := 0 // 注意,此處存儲的是 Ra 中 Sb 的個數,而非 Ra 中 Rb 的個數for index1/len1 < n1 { // 遍歷整個 Raif index1%len1 == len1-1 { //在 Sa 末尾if val, ok := map1[index2%len2]; ok { // 出現了循環,進行快進cycleLen := index1/len1 - val/len1 // 每個循環占多少個 SacycleNum := (n1 - 1 - index1/len1) / cycleLen // 還有多少個循環cycleS2Num := index2/len2 - map2[index2%len2]/len2 // 每個循環含有多少個 Sbindex1 += cycleNum * cycleLen * len1 // 將 Ra 快進到相應的位置ans += cycleNum * cycleS2Num // 把快進部分的答案數量加上} else { // 第一次,注意存儲的是未取模的map1[index2%len2] = index1map2[index2%len2] = index2}}if s1[index1%len1] == s2[index2%len2] {if index2%len2 == len2-1 {ans += 1}index2 += 1}index1 += 1}return ans / n2 }

總結

以上是生活随笔為你收集整理的466. 统计重复个数 golang[转]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。