일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 시바견
- data science
- Python Code
- 715. Range Module
- DWG
- Regular Expression
- Substring with Concatenation of All Words
- attribute
- 프로그래머스
- 밴픽
- concurrency
- Protocol
- 컴퓨터의 구조
- LeetCode
- 315. Count of Smaller Numbers After Self
- Convert Sorted List to Binary Search Tree
- shiba
- Decorator
- 30. Substring with Concatenation of All Words
- Generator
- iterator
- Python
- kaggle
- t1
- Class
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- Python Implementation
- 43. Multiply Strings
- 파이썬
Archives
- Today
- Total
Scribbling
[C++] Deque<int> 본문
https://leetcode.com/problems/sliding-window-maximum/
class Solution {
public:
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
vector<int> ret;
deque<int> q;
for(int i=0; i<nums.size(); i++) {
while (not q.empty() and q[0] == i - k) {
q.pop_front();
}
while (not q.empty() and nums[q[q.size()-1]] < nums[i]) {
q.pop_back();
}
q.push_back(i);
if (i >= k - 1) {
ret.push_back(nums[q[0]]);
}
}
return ret;
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] Abstract Class, Interface, Multiple Inheritance (0) | 2024.02.14 |
---|---|
[C++] lower_bound (0) | 2024.02.06 |
[C++] 전문가를 위한 C++ - Chapter 8 (0) | 2023.10.07 |
[C++] find, deque, bfs, structured binding (0) | 2023.09.30 |
[C++] Smart pointers (0) | 2023.09.30 |