建公司网站哪里好,做公司网站的流程,邯郸网站制作个人,网站页脚怎么做题目#xff1a;给定一个只包括 ‘(’#xff0c;‘)’#xff0c;‘{’#xff0c;‘}’#xff0c;‘[’#xff0c;‘]’ 的字符串 s #xff0c;判断字符串是否有效。 有效字符串需满足#xff1a; 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合…题目给定一个只包括 ‘(’‘)’‘{’‘}’‘[’‘]’ 的字符串 s 判断字符串是否有效。 有效字符串需满足 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 每个右括号都有一个对应的相同类型的左括号。
#includeiostream
#includevector
#includemap
#includeunordered_map
#includestack
using namespace std;unordered_mapchar, char up {{( , )},{{ , }},{[ , ]},
};class Solution
{
public:bool isValid(string s){stackchar st;for (char c : s){if (up.count(c)) //判断c是否是up的键,是的话就压栈{st.push(c); }else if(st.empty() || up[st.top()] ! c){return false;}else //up[st.top()] c{st.pop();}}return st.empty();}
};int main()
{Solution a;cout a.isPalindrome : a.isValid({([])}) endl;return 0;
}