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