Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- bool isValid(string s) {
- stack<char>st;
- int n = (int)s.size();
- for(int i=0;i<n;i++)
- {
- if(s[i] =='{' || s[i] == '(' || s[i] =='[')
- {
- st.push(s[i]);
- continue;
- }
- if(st.size() <= 0) return 0;
- else{
- char open = st.top();
- char close = s[i];
- if(open == '{' && close !='}'
- or open =='[' && close !=']'
- or open == '(' && close != ')'
- )
- return false;
- st.pop();
- }
- }
- return st.empty();
- }
- };
Add Comment
Please, Sign In to add comment