<awangdev>1249. Minimum Remove to Make Valid Parentheses_1.java
public String minRemoveToMakeValid(String s) {

        Set<Integer> set = new HashSet<>();
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(') stack.push(i);
            if (c == ')') {
                if (!stack.isEmpty()) stack.pop();
                else set.add(i); 
            }
        }
        while (!stack.isEmpty()) set.add(stack.pop());
        
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            if (!set.contains(i)) sb.append(s.charAt(i));
        }

        return sb.toString();
    }
public String var_0 ( String var_2 ) {
  Set < Integer > var_6 = new HashSet < > ( ) ;
  Stack < Integer > var_8 = new Stack < > ( ) ;
  for ( int var_10 = 0 ;
  var_10 < var_2 . length ( ) ;
  var_10 ++ ) {
    char var_13 = var_2 . charAt ( var_10 ) ;
    if ( var_13 == '(' ) var_8 . push ( var_10 ) ;
    if ( var_13 == ')' ) {
      if ( ! var_8 . isEmpty ( ) ) var_8 . pop ( ) ;
      else var_6 . add ( var_10 ) ;
    }
  }
  while ( ! var_8 . isEmpty ( ) ) var_6 . add ( var_8 . pop ( ) ) ;
  StringBuffer var_21 = new StringBuffer ( ) ;
  for ( int var_10 = 0 ;
  var_10 < var_2 . length ( ) ;
  var_10 ++ ) {
    if ( ! var_6 . contains ( var_10 ) ) var_21 . append ( var_2 . charAt ( var_10 ) ) ;
  }
  return var_21 . toString ( ) ;
}
