Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/11/16 10:40), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1125/1554 (看更多)
3254. Find the Power of K-Size Subarrays I ## 思路 left = subarray的起始idx 掃陣列檢查 當前的num是否為前一數+1, 不是就更新left ## Code ```python class Solution: def resultsArray(self, nums: List[int], k: int) -> List[int]: if k == 1: return nums res = [] n = len(nums) left = 0 for i in range(1, n): if nums[i] != nums[i-1] + 1: left = i if i + 1 < k: continue res.append(nums[i] if i - k + 1 >= left else -1) return res ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.187 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1731724804.A.3A3.html
文章代碼(AID): #1dE0O4EZ (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dE0O4EZ (Marginalman)