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
|
1635 Discussions
|
Please Login in order to post a comment
JAVA 8
public static String isBalanced(String s) { String response = "YES"; String[] values = s.split(""); String listExpected = ""; String passValues = "({[";
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)