※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.187 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1731724804.A.3A3.html
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
```
--