Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool wordInLanguage(string s) {
- stack<char> st;
- for(int c=0;c<s.size();c++) {
- if(s[c] == '}') {
- if(st.empty() || st.top() != '{') return false;
- st.pop();
- }
- else if(s[c] == ']') {
- if(st.empty() || st.top() != '[') return false;
- st.pop();
- }
- else if(s[c] == ')') {
- if(st.empty() || st.top() != '(') return false;
- st.pop();
- } else if(s[c] != '(' && s[c] != '{' && s[c] != '[') {
- return false;
- } else {
- st.push(s[c]);
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement