classSolution{public:boolisValid(string s){
unordered_map<char,char> mp ={{'(',')'},{'{','}'},{'[',']'}};
stack<char> st;if(s.size()%2==1){returnfalse;}for(char c:s){if(c =='('|| c =='['| c =='{'){
st.push(c);}elseif(st.empty()|| mp[st.top()]!= c){returnfalse;}else{
st.pop();}}return st.empty();}};
1047 删除字符串中的所有相邻重复项
classSolution{public:
string removeDuplicates(string s){
string ans ="";for(char c:s){if(c != ans.back()){
ans += c;}else{
ans.erase(ans.size()-1,1);}}return ans;}};
150 逆波兰表达式求值
classSolution{public:intevalRPN(vector<string>& tokens){
stack<int> st;for(auto s:tokens){if(IsNum(s)){int x =stoi(s);
st.push(x);}else{int a = st.top();
st.pop();int b = st.top();
st.pop();int ans;if(s =="+"){
ans = a + b;}elseif(s =="-"){
ans = b - a;}elseif(s =="/"){
ans = b/a;}else{
ans = a * b;}
st.push(ans);}}return st.top();}boolIsNum(string s){if(s.size()>1|| s[0]>='0'&& s[0]<='9'){returntrue;}returnfalse;}};