当前位置:网站首页>[Jianzhi offer] Jianzhi offer 09 Implementing queues with two stacks
[Jianzhi offer] Jianzhi offer 09 Implementing queues with two stacks
2022-06-12 21:52:00 【Caicai 2022】
subject
Code
Execution time :364 ms, In all Python3 Defeated in submission 39.23% Users of
Memory consumption :19 MB, In all Python3 Defeated in submission 24.23% Users of
Pass the test case :55 / 55
class CQueue:
def __init__(self):
self.stack1=[]
self.stack2=[]
def appendTail(self, value: int) -> None:
self.stack1.append(value)
def deleteHead(self) -> int:
if not len(self.stack1) and not len(self.stack2):
return -1
else:
if len(self.stack2):
temp=self.stack2[-1]
self.stack2.pop()
return temp
else:
while len(self.stack1):
temp=self.stack1[-1]
self.stack1.pop()
self.stack2.append(temp)
self.stack2.pop()
return temp
# Your CQueue object will be instantiated and called as such:
# obj = CQueue()
# obj.appendTail(value)
# param_2 = obj.deleteHead()
边栏推荐
- [qnx hypervisor 2.2 manuel de l'utilisateur] 4.2 environnement de construction pris en charge
- What is the difference between volatile variables and atomic variables?
- Linux backup MySQL
- gzip压缩解压缩
- Ansible Roles-项目案例(四)
- 有向图深拷贝
- Zip compression decompression
- ICML2022 | GALAXY:極化圖主動學習
- 同花顺能开户吗,在同花顺开户安全么,证券开户怎么开户流程
- Compiling process of OpenSSL and libevent on PC
猜你喜欢
CVPR 2022 | 应对噪声标签,西安大略大学、字节跳动等提出对比正则化方法
Ansible PlayBook et ansible roles (3)
Ansible summary (VI)
SQL tuning guide notes 10:optimizer statistics concepts
How do complex systems detect anomalies? North Carolina UNCC and others' latest overview of graph based deep learning anomaly detection methods in complex distributed systems describes the latest prog
ICML2022 | GALAXY:极化图主动学习
Cookies and sessions
Icml2022 | Galaxy: apprentissage actif des cartes de polarisation
Producer consumer model under multithreading model
Xingda easy control ModbusRTU to modbustcp gateway
随机推荐
How do complex systems detect anomalies? North Carolina UNCC and others' latest overview of graph based deep learning anomaly detection methods in complex distributed systems describes the latest prog
【QNX Hypervisor 2.2 用户手册】4.2 支持的构建环境
What is your understanding of thread priority?
Pixel level reconstruction and restoration technology to solve severe image blur
【目标检测】|Dive Deeper Into Box for Object Detection 基于FCOS新训练方法
Ansible playbook and ansible roles (III)
ICML2022 | GALAXY:极化图主动学习
Yyds dry goods inventory solution sword finger offer: the first non repeated character in the character stream
Deep Hough voting for 3D object detection in point clouds
大学期间零基础如何开展编程学习
Semester summary of freshman year
(4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)
Oracle 19C installation documentation
VagrantBox重新安装vboxsf驱动
SQL调优指南笔记17:Importing and Exporting Optimizer Statistics
MySQL介绍和安装(一)
[QNX hypervisor 2.2 user manual] 4.4 build host
Zip压缩解压缩
Libmysqlclient A static library
SQL调优指南笔记11:Histograms