Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. bool wordInLanguage(string s) {
  2.     stack<char> st;
  3.  
  4.     for(int c=0;c<s.size();c++) {
  5.         if(s[c] == '}') {
  6.             if(st.empty() || st.top() != '{') return false;
  7.             st.pop();
  8.         }
  9.         else if(s[c] == ']') {
  10.             if(st.empty() || st.top() != '[') return false;
  11.             st.pop();
  12.         }
  13.         else if(s[c] == ')') {
  14.             if(st.empty() || st.top() != '(') return false;
  15.             st.pop();
  16.         } else if(s[c] != '(' && s[c] != '{' && s[c] != '[') {
  17.             return false;
  18.         } else {
  19.             st.push(s[c]);
  20.         }
  21.     }
  22.     return true;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement