title: Parenthesis/Brackets Matching using Stack algorithm
body: <p>For example if the parenthesis/brackets is matching in the following:</p>
  
  <pre><code>({})
  (()){}()
  ()
  </code></pre>
  
  <p>and so on but if the parenthesis/brackets is not matching it should return false, eg:</p>
  
  <pre><code>{}
  ({}(
  ){})
  (()
  </code></pre>
  
  <p>and so on. Can you please check this code? Thanks in advance.</p>
  
  <pre class="lang-java prettyprint-override"><code>public static boolean isParenthesisMatch(String str) {
      Stack&lt;Character&gt; stack = new Stack&lt;Character&gt;();
  
      char c;
      for(int i=0; i &lt; str.length(); i++) {
          c = str.charAt(i);
  
          if(c == '{')
              return false;
  
          if(c == '(')
              stack.push(c);
  
          if(c == '{') {
              stack.push(c);
              if(c == '}')
                  if(stack.empty())
                      return false;
                  else if(stack.peek() == '{')
                      stack.pop();
          }
          else if(c == ')')
              if(stack.empty())
                  return false;
              else if(stack.peek() == '(')
                      stack.pop();
                  else
                      return false;
          }
          return stack.empty();
  }
  
  public static void main(String[] args) {        
      String str = "({})";
      System.out.println(Weekly12.parenthesisOtherMatching(str)); 
  }
  </code></pre>