题解 | #用两个栈实现队列#

用两个栈实现队列

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();
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务