Queue 2개로 Stack구현하기 import java.util.LinkedList; import java.util.Queue; public class Stack { private Queue q1; private Queue q2; public Stack() { this.q1 = new LinkedList(); this.q2 = new LinkedList(); } public void push(T value) { q1.add(value); } public T pop() { while (q1.size() > 1) { q2.add(q1.poll()); } Queue temp = q1; q1 = q2; q2 = temp; return q2.poll(); } @Override public String toStr..
stack
Stack 두개를 이용하여 Queue구현하기 자바 import java.util.Stack; class Queue { Stack inStack; Stack outStack; public Queue() { this.inStack = new Stack(); this.outStack = new Stack(); } public void enqueue(T value) { inStack.add(value); } public T dequeue() { if (!inStack.isEmpty()) { while(!inStack.isEmpty()) { outStack.add(inStack.pop()); } } return outStack.pop(); } @Override public String toString() { re..
https://leetcode.com/problems/daily-temperatures/description/ Daily Temperatures - LeetCode Daily Temperatures - Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for w leetcode.com class Solution: def dailyTemperature..