class MyQueue{
        private Stack<Integer> in = new Stack<>();
        private Stack<Integer> out = new Stack<>();
        
        public void push(int x){
            in.push(x);
        }
        
        public int pop(){
            if(out.isEmpty()){
                while(!in.isEmpty()){
                    out.push(in.pop());
                }
            }
            return out.pop();
        }
        
        public int peek(){
            if(out.isEmpty()){
                while(!in.isEmpty()){
                    out.push(in.pop());
                }
            }
            return out.peek();
        }
        
        public boolean empty(){
            return in.isEmpty() && out.isEmpty();
        }
    }

 

相关文章:

  • 2021-12-11
  • 2021-07-31
  • 2021-11-08
  • 2022-12-23
  • 2021-08-23
  • 2021-09-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2021-08-06
  • 2021-12-11
  • 2021-07-02
相关资源
相似解决方案