add: 230828

This commit is contained in:
Eatswap 2023-08-28 23:58:03 +08:00
parent 9860bb7a54
commit 7f8946ce7a
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 54 additions and 0 deletions

40
cpp/2308/LC230828.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <queue>
class LC230828 {
private:
std::queue<int> q;
public:
LC230828();
void push(int x);
int pop();
int top();
bool empty();
};
LC230828::LC230828() = default;
void LC230828::push(int x) {
int n = q.size();
q.push(x);
while (n--) {
q.push(q.front());
q.pop();
}
}
int LC230828::pop() {
int ret = q.front();
q.pop();
return ret;
}
int LC230828::top() {
return q.front();
}
bool LC230828::empty() {
return q.empty();
}

View File

@ -1,6 +1,7 @@
#ifndef LEETCODE_CPP_DEFS_H #ifndef LEETCODE_CPP_DEFS_H
#define LEETCODE_CPP_DEFS_H #define LEETCODE_CPP_DEFS_H
#include <queue>
#include <vector> #include <vector>
class LC230827 { class LC230827 {
@ -8,4 +9,17 @@ public:
static bool canCross(const std::vector<int>&); static bool canCross(const std::vector<int>&);
}; };
class LC230828 {
private:
std::queue<int> q;
public:
LC230828();
void push(int x);
int pop();
int top();
bool empty();
};
#endif //LEETCODE_CPP_DEFS_H #endif //LEETCODE_CPP_DEFS_H