题解 | #用两个栈实现队列#
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
using System.Collections.Generic;
class Solution
{
Stack<int> sta1 = new Stack<int>();
Stack<int> sta2 = new Stack<int>();
int num2 = 0;
public void push(int node)
{
sta1.Push(node);
}
public int pop()
{
if(num2 == 0){
for(int i = sta1.Count; i > 0; i--){
sta2.Push(sta1.Pop());
num2++;
}
}
num2--;
return sta2.Pop();
}
}
