We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class MinStack { public: void push(int x) { stack_.push_front(x); if (minStack_.empty() || x < *minStack_.front()) { minStack_.push_front(&stack_.front()); } } void pop() { if (&stack_.front() == minStack_.front()) { minStack_.pop_front(); } stack_.pop_front(); } int top() { return stack_.front(); } int getMin() { return *minStack_.front(); } private: deque<int> stack_; deque<int*> minStack_; };
This puzzle really sucks for C++ programers. :-( However the OJ just provide the Java solution.
The text was updated successfully, but these errors were encountered:
I view the source code of the STL (from both clang++ and g++):
std::deque uses a “split buffer” to store the pointers of the new int. And the new capacity is the double of the old one.
std::deque
int
It's still confusing.
Sorry, something went wrong.
No branches or pull requests
This puzzle really sucks for C++ programers. :-( However the OJ just provide the Java solution.
The text was updated successfully, but these errors were encountered: