Consider the following code. It is for check if the String has valid parenthesis but without using stack.
public boolean isValid(String input) {
while(input.length() != (input = input.replaceAll("\\(\\)|\\[\\]|\\{\\}", "")).length());
return input.isEmpty();
}
But Kinda difficult to understand. Can this be simplified? Without adding more number of new lines?