shenmuxin

Results 1 issues of shenmuxin

[【栈与队列 2.用栈实现队列】](https://www.programmercarl.com/0232.%E7%94%A8%E6%A0%88%E5%AE%9E%E7%8E%B0%E9%98%9F%E5%88%97.html#python) ```python3 class MyQueue: ... def push(self, x: int) -> None: """ 有新元素进来,就往in里面push """ self.stack_in.append(x) ``` 如果我们使用`pop()`之后立马使用`push()`,那么存放的相对顺序就有误了,所以在函数`push`中,我们应该将`stack_out`中的数据先恢复到`stack_int`中,即: ```python3 class MyQueue: ... def push(self, x: int) -> None: while self.stack_out:...