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

用两个栈实现队列

http://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6

import java.util.Stack;

public class Solution {
Stack<integer> stack1 = new Stack<integer>();
Stack<integer> stack2 = new Stack<integer>();</integer></integer></integer></integer>

public void push(int node) {
    stack1.push(node);
}

public int pop() {
    if(!stack2.isEmpty()){
        return stack2.pop();
    }
    while(!stack1.isEmpty()){
        stack2.push(stack1.pop());
    }
    return stack2.pop();

}

}

全部评论

相关推荐

2025-12-22 15:04
江西农业大学 Web前端
SaviorSu:直接说下学期可以请假,一般情况学校允许我26届,大三就直接去实习了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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