当前位置:网站首页>622. 设计循环队列
622. 设计循环队列
2022-08-03 11:59:00 【anieoo】
原题链接:622. 设计循环队列

solution:
class MyCircularQueue {
public:
int hh = 0,tt = 0;
vector<int> q;
MyCircularQueue(int k) {
q.resize(k + 1);
}
bool enQueue(int value) {
if(isFull()) return false;
q[tt++] = value;
if(tt == q.size()) tt = 0;
return true;
}
bool deQueue() {
if (isEmpty()) return false;
hh ++ ;
if (hh == q.size()) hh = 0;
return true;
}
int Front() {
if(isEmpty()) return -1;
return q[hh];
}
int Rear() {
if (isEmpty()) return -1;
int t = tt - 1;
if (t < 0) t = q.size() - 1;
return q[t];
}
bool isEmpty() {
return hh == tt;
}
bool isFull() {
return (tt + 1) % q.size() == hh;
}
};
/**
* Your MyCircularQueue object will be instantiated and called as such:
* MyCircularQueue* obj = new MyCircularQueue(k);
* bool param_1 = obj->enQueue(value);
* bool param_2 = obj->deQueue();
* int param_3 = obj->Front();
* int param_4 = obj->Rear();
* bool param_5 = obj->isEmpty();
* bool param_6 = obj->isFull();
*/
边栏推荐
- 基于SSM和Web实现的农作物生长监控系统
- 4500字归纳总结,一名软件测试工程师需要掌握的技能大全
- 距LiveVideoStackCon 2022 上海站开幕还有3天!
- 实现2d人物在跳跃的同时左右移动
- -树的高度-
- 常用lambda表达式
- Explain the virtual machine in detail!JD.com produced HotSpot VM source code analysis notes (with complete source code)
- opencv学习—VideoCapture 类基础知识「建议收藏」
- [论文阅读] (23)恶意代码作者溯源(去匿名化)经典论文阅读:二进制和源代码对比
- What knowledge points do you need to master to learn software testing?
猜你喜欢

本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现

TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践

OFDM 十六讲 4 -What is a Cyclic Prefix in OFDM

面试突击71:GET 和 POST 有什么区别?

第四周学习 HybridSN,MobileNet V1,V2,V3,SENet

MySQL之json数据操作

笔试题:金额拆分

最牛逼的集群监控系统,它始终位列第一!

asdn涨薪技术之apifox+Jenkins如何玩转接口自动化测试

"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
随机推荐
基于Sikuli GUI图像识别框架的PC客户端自动化测试实践
The effects of the background and the Activiti
使用.NET简单实现一个Redis的高性能克隆版(一)
Cookie and Session usage
asdn涨薪技术之apifox+Jenkins如何玩转接口自动化测试
劝退背后。
LeetCode刷题笔记:622.设计循环队列
[深入浅出]三位数排序
"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
87.(cesium之家)cesium热力图(贴地形)
Vs 快捷键---探索不一样的编程
从零开始Blazor Server(6)--基于策略的权限验证
CDH6.3.2开启kerberos认证
[Wrong title] Circuit maintenance
【一起学Rust】Rust包管理工具Cargo初步了解
常用lambda表达式
第4章 搭建网络库&Room缓存框架
hystrix 服务熔断和服务降级
From scratch Blazor Server (6) - authentication based on strategy
直播弱网优化