Class MinStack
Easy
Execution time limit is 7 seconds
Runtime memory usage limit is 128 megabytes
Implement a stack data structure that supports next operations:
push n - Add to the stack the number n.
pop - Remove the last element from the stack. Print the value of removed element.
top - Print the value of the top element, not removing it from the stack.
GetMin - Print the value of the minimum element in the stack.
size - Print the number of elements in the stack.
Write the code according to the next interface:
class MyStack // C++ { private: stack<int> s, mn; // s - normal stack, mn - minimum stack public: void push(int x); // Push x into the stack int pop(void); // Remove and return the element from the top of the stack int top(void); // Return the element from the top of the stack int GetMin(void); // Return the minimum element from the stack int GetSize(void); // Return the size of the stack };
class MyStack // Java { private stack<Integer> s, mn; // s - normal stack, mn - minimum stack MyStack() // Constructor public void push(int x); // Push x into the stack public int pop(void); // Remove and return the element from the top of the stack public int top(void); // Return the element from the top of the stack public int GetMin(void); // Return the minimum element from the stack public int GetSize(void); // Return the size of the stack };
Input
Each line contains a single command.
Output
For each command print on a separate line the corresponding result.
Examples
Input #1
Answer #1
Submissions 955
Acceptance rate 18%