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.
importjava.util.*;classSolution{publicstaticbooleancheck(Stringinput){Stack<Character>s=newStack<Character>();for(charc:input.toCharArray()){if(c=='{'){s.push('}');}elseif(c=='['){s.push(']');}elseif(c=='('){s.push(')');}elseif(s.isEmpty()||s.pop()!=c){returnfalse;}}returns.isEmpty();}publicstaticvoidmain(String[]argh){Scannersc=newScanner(System.in);while(sc.hasNext()){Stringinput=sc.next();//Complete the codeSystem.out.println(check(input));}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Stack
You are viewing a single comment's thread. Return to all comments →