class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
if(!stack1.empty() && stack2.empty()){
while(!stack1.empty()){
stack2.push(stack1.top());
stack1.pop();
}
}
int res = stack2.top();
stack2.pop();
return res;
}
private:
stack<int> stack1;
stack<int> stack2;
};
class Solution {
public:
stack<int> sta, sta_min;
void push(int val) {
sta.push(val);
if(sta_min.empty() || val <= sta_min.top()) sta_min.push(val);
}
void pop() {
if(sta.top() == sta_min.top()) sta_min.pop();
sta.pop();
}
int top() {
return sta.top();
}
int min() {
return sta_min.top();
}
};
class Solution {
public:
bool IsPopOrder(vector<int>& pushV, vector<int>& popV) {
stack<int> sta;
int i, j;
for(i = 0, j = 0; i < pushV.size(); i++){
sta.push(pushV[i]);
while(!sta.empty() && sta.top() == popV[j]) {sta.pop(); j++;}
}
if(i == j) return true;
else return false;
}
};
class Solution {
public:
string ReverseSentence(string str) {
Myreverse(str, 0 , str.size() - 1);
for(int i = 0, j = 0; j < str.size(); j++){
if(j == str.size() - 1 || str[j + 1] == ' ') {
Myreverse(str, i, j);
i = j + 2;
}
}
return str;
}
void Myreverse(string& str, int left, int right){
while(left < right){
swap(str[left], str[right]);
left++; right--;
}
}
};
class Myqueue{
public:
deque<int> deq;
void push(int val){
if(deq.empty() || val <= deq.back()) deq.push_back(val);
else {
while(!deq.empty() && val > deq.back()) deq.pop_back();
deq.push_back(val);
}
}
void pop(int val){
if(!deq.empty() && val == deq.front()) deq.pop_front();
}
int top(){
return deq.front();
}
};
class Solution {
public:
vector<int> maxInWindows(vector<int>& num, int size) {
vector<int> res;
if(size < 1 || size > num.size()) return res;
Myqueue que;
for(int i = 0; i < size; i++) que.push(num[i]);
res.push_back(que.top());
for(int i = size; i < num.size(); i++){
que.push(num[i]);
que.pop(num[i - size]);
res.push_back(que.top());
}
return res;
}
};