일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 화상영어
- 개발자
- 운동
- 만화도
- Writing
- 3줄정리
- 읽기
- 괜찮음
- leetcode
- 30분
- 매일
- 사이드
- 쓰릴오브파이트
- FIT XR
- English
- 영어공부
- 뭐든
- 리얼 클래스
- Problem Solving
- Daily Challenge
- 미드시청
- realclass
- 프로젝트
- 10분
- 잡생각
- 스탭퍼
- 월간
- 파비최
- 영어원서읽기
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.08.16 Today's Challenge 본문
https://leetcode.com/problems/sliding-window-maximum/
Sliding Window Maximum - LeetCode
Can you solve this real interview question? Sliding Window Maximum - You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the wind
leetcode.com
슬라이딩 윈도우 문제 풀기
class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
dq = deque()
res = []
for i in range(k):
while dq and nums[i] >= nums[dq[-1]]:
dq.pop()
dq.append(i)
res.append(nums[dq[0]])
for i in range(k, len(nums)):
if dq and dq[0] == i - k:
dq.popleft()
while dq and nums[i] >= nums[dq[-1]]:
dq.pop()
dq.append(i)
res.append(nums[dq[0]])
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.08.18 Today's Challenge (0) | 2023.08.18 |
---|---|
2023.08.17 Today's Challenge (0) | 2023.08.17 |
2023.08.15 Today's Challenge (0) | 2023.08.15 |
2023.08.14 Today's Challenge (0) | 2023.08.14 |
2023.08.13 Today's Challenge (0) | 2023.08.13 |
Comments