title: Check for Valid Parentheses in java
body: <p>I'm trying to find out if the given input is a valid parentheses or not. The input string is made of '(', ')', '{', '}', '[' and ']' .<br>
  An input string is valid if:</p>
  
  <p>1.Open brackets must be closed by the same type of brackets.<br>
  2.Open brackets must be closed in the correct order.
  3. empty strings are valid</p>
  
  <p>However my code below using recursion is not working on the valid cases. It is suppose to go to the base case (when input is "") but instead goes to the return statement after the for loop. </p>
  
  <pre><code>class Solution {
  
      public boolean validParen(String input) {
  
          if(input.isEmpty()) {
              return true;
          }
  
          else {
              for (int i = 0; i &lt; input.length() - 1; i++) {
                  if ((input.charAt(i) == '(' &amp;&amp; input.charAt(i + 1) == ')') ||
                          (input.charAt(i) == '{' &amp;&amp; input.charAt(i + 1) == '}') ||
                          (input.charAt(i) == '[' &amp;&amp; input.charAt(i + 1) == ']')) {
                      input = input.substring(0, i) + input.substring(i + 2);
                      System.out.println("Input is " + input);
                      validParen(input);
                  }
              }
              return false;
          }
      }
  
      public static void main(String[] args) {
          Solution sol = new Solution();
          //System.out.println(sol.validParen("")); 
          //System.out.println(sol.validParen("()")); // returns false for some reason 
          //System.out.println(sol.validParen("()[]{}")); // returns false for some reason
          //System.out.println(sol.validParen("(]"));
          //System.out.println(sol.validParen("([)]"));
          //System.out.println(sol.validParen("{[]}")); // returns false for some reason
      }
  }
  </code></pre>