栈
bala
Matts Tian
这个作者很懒,什么都没留下…
展开
-
有效的括号
class Solution {public: bool isValid(string s) { int n = s.size(); if(n % 2 == 1) return false; unordered_map<char, char> pairs = { {')', '('}, {']', '['}, {'}', '{'} }; stack<char> stk; for(.原创 2021-03-17 08:23:20 · 149 阅读 · 0 评论 -
包含 min 函数的栈
class MinStack {private: stack<int> a; stack<int> b;public: /** initialize your data structure here. */ MinStack() { } void push(int x) { a.push(x); if(b.empty() || x <= b.top()) { .原创 2021-03-16 20:48:41 · 74 阅读 · 0 评论 -
用两个栈实现队列
class CQueue { stack<int> stack1, stack2;public: CQueue() { while(!stack1.empty()) { stack1.pop(); } while(!stack2.empty()) { stack2.pop(); } } void appendTail(int value) { stack1.pus.原创 2021-03-16 20:46:09 · 64 阅读 · 0 评论