We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
stringisBalanced(strings){// Complete this functionstd::stack<char>st;st.push('@');for(inti=0;i<s.length();i++){if(s[i]=='('||s[i]=='['||s[i]=='{')st.push(s[i]);else{while(!st.empty()&&((s[i]==')'&&st.top()=='(')||(s[i]==']'&&st.top()=='[')||(s[i]=='}'&&st.top()=='{'))){st.pop();}}}if(st.top()=='@')return"YES";elsereturn"NO";}
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
why this code fail for two of the testcases.