Re: [閒聊] 每日leetcode

看板Marginalman作者 (神楽めあ的錢包)時間1年前 (2024/12/10 20:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1193/1554 (看更多)
2981. Find Longest Special Substring That Occurs Thrice I 思路 直接兩個for迴圈下去 紀錄每個符合題目要求的字串次數 超過三次就看長度是多少 並且維持最大長度 golang code func maximumLength(s string) int { rec := make(map[string]int) n, ans := len(s), -1 for i := 0; i < n; i++ { for j := i; j < n; j++ { if s[i] == s[j] { rec[s[i:j+1]]++ if rec[s[i:j+1]] >= 3 { ans = max(ans, len(s[i:j+1])) } } else { break } } } return ans } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.71.213.204 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1733833975.A.BB4.html
文章代碼(AID): #1dM3Jtkq (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dM3Jtkq (Marginalman)