148ms c# accepted solution


  • 0
    X

    public class Stack {
    Queue<int> queue = new Queue<int>();

    // Push element x onto stack.
    public void Push(int x) {
        queue.Enqueue(x);
    }
    
    // Removes the element on top of the stack.
    public void Pop() {
        int[] temp = queue.ToArray();
        queue.Clear();
        for(int i = 0; i < temp.Length - 1; ++i)
            queue.Enqueue(temp[i]);
    }
    
    // Get the top element.
    public int Top() {
        int[] temp = queue.ToArray();
        return temp[temp.Length - 1];
    }
    
    // Return whether the stack is empty.
    public bool Empty() {
        return queue.Count == 0;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.