일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 109. Convert Sorted List to Binary Search Tree
- concurrency
- Generator
- 파이썬
- Python
- Python Implementation
- LeetCode
- 43. Multiply Strings
- Protocol
- 밴픽
- Regular Expression
- kaggle
- DWG
- Class
- Python Code
- 715. Range Module
- 컴퓨터의 구조
- t1
- Convert Sorted List to Binary Search Tree
- iterator
- Substring with Concatenation of All Words
- 운영체제
- 315. Count of Smaller Numbers After Self
- data science
- 30. Substring with Concatenation of All Words
- 시바견
- 프로그래머스
- Decorator
- shiba
- attribute
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 |