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.nextLine(); //Complete the code HashMap<Character,Integer> hm = new HashMap<>(); hm.put('(',0);hm.put('[',0);hm.put('{',0);hm.put(')',0);hm.put(']',0);hm.put('}',0); for(int i=0;i<input.length();i++) { int existing = hm.get(input.charAt(i)); hm.put(input.charAt(i),existing+1); } if(input.endsWith("{") || input.endsWith("(") || input.endsWith("[")) System.out.println(false); else if(hm.get('(')==hm.get(')') && hm.get('{')==hm.get('}') && hm.get('[')==hm.get(']')) 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{
}