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.
Balanced Brackets
Balanced Brackets
Sort by
recency
|
1634 Discussions
|
Please Login in order to post a comment
use a lifo queue and scan left to right
What's the issue?
include
using namespace std; void printstack(stack s){ while(!s.empty()){ cout< st; bool t=true; for (auto ch:s){ if ((ch=='(')||(ch=='[') || (ch=='{')){ st.push(ch); //printstack(st); }else{ if ((ch==')') && (st.top()=='(')){ st.pop(); }else if((ch==']') &&(st.top()=='[')){ st.pop(); }else if((ch=='}') && (st.top()=='{')){ st.pop(); }else{ return "NO"; } } }
} int main(){ int t; cin>>t; while(t--){ string s; cin>>s; cout<
I try a recursive solution just for fun (won't pass the test cases)
Fairly simple Stack based problem. Nothing too complex.
Here's my Java 8 solution, passing all test cases, for Max Score of 25: