You are viewing a single comment's thread. Return to all comments →
class Solution{
public static void main(String []argh) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s = sc.nextLine(); int n = s.length(); int counter = 0; int counter1 = 0; if(s.startsWith("}") || s.startsWith("]") || s.startsWith(")")){ System.out.println("false"); }else if(s.endsWith("(") || s.endsWith("{") || s.endsWith("[")){ System.out.println("false"); }else { for (int i = 0; i < n; i++) { if (s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') { counter++; } if (s.charAt(i) == ')' || s.charAt(i) == ']' || s.charAt(i) == '}') { counter1++; } } if (counter == counter1) { System.out.println("true"); } else { System.out.println("false"); } } }
} }
isnt this solution just wrong for this input {(}) ?
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Java Stack
You are viewing a single comment's thread. Return to all comments →
class Solution{
} }
isnt this solution just wrong for this input {(}) ?