Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca576c5

Browse files
更正 0232.用栈实现队列.md python代码
添加限制条件,仅在栈不为空的情况下才允许后续pop()和peek()的操作
1 parent 8b94306 commit ca576c5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

‎problems/0232.用栈实现队列.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ class MyQueue:
304304
2. 如果out没有元素,就把in里面的元素(除了第一个)依次pop后装进out里面
305305
3. 直接把in剩下的元素pop出来,就是queue头部的
306306
"""
307+
if self.empty:
308+
return None
309+
307310
if self.stack_out:
308311
return self.stack_out.pop()
309312
else:
@@ -317,6 +320,9 @@ class MyQueue:
317320
1. 查out有没有元素,有就把最上面的返回
318321
2. 如果out没有元素,就把in最下面的返回
319322
"""
323+
if self.empty:
324+
return None
325+
320326
if self.stack_out:
321327
return self.stack_out[-1]
322328
else:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /