You are viewing a single comment's thread. Return to all comments →
import java.util.*; class Solution{
public static void main(String []argh) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String input=sc.next(); //Complete the code Stack <Character> s = new Stack<>(); for(int i = 0 ; i<input.length(); i++) { char c = input.charAt(i); if(c=='{' || c=='(' || c=='[') { s.push(c); } else if(s.size()!=0 && ((c=='}' && s.peek()=='{') || (c==')' && s.peek()=='(') || (c==']' && s.peek()=='['))) { s.pop(); } else{ s.push(c); } } if(s.size()==0) System.out.println("true"); else System.out.println("false"); } }
}
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 →
import java.util.*; class Solution{
}