content: package codingquestions.leetcode;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Stack;
  
  /*
   * 20. Valid Parentheses
  Easy
  
  14708
  
  713
  
  Add to List
  
  Share
  Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
  
  An input string is valid if:
  
  Open brackets must be closed by the same type of brackets.
  Open brackets must be closed in the correct order.
   
  
  Example 1:
  
  Input: s = "()"
  Output: true
  Example 2:
  
  Input: s = "()[]{}"
  Output: true
  Example 3:
  
  Input: s = "(]"
  Output: false
   
  
  Constraints:
  
  1 <= s.length <= 104
  s consists of parentheses only '()[]{}'.
   * 
   */
  public class ValidParenthesis {
      public static void main(String[] args) {
          var vp = new ValidParenthesis();
          System.out.println(vp.isValid("()[]{}"));
      }
  
      public boolean isValid(String s) {
          Map<Character, Character> mappings = new HashMap<Character, Character>() {{
              put(')', '(');
              put('}', '{');
              put(']', '[');
          }};
  
          Stack<Character> letters = new Stack<>();
  
          for (int i = 0; i < s.length(); i++) {
              char temp = s.charAt(i);
              if (mappings.containsKey(temp)) {
                  if (letters.isEmpty() || letters.pop() != mappings.get(temp)) {
                      return false;
                  }
              } else {
                  letters.push(temp);
              }
          }
          return letters.isEmpty();
      }
  }
  