<awangdev>301. Remove Invalid Parentheses_1.java
private void dfs(List<String> rst, String s, int i, int j, char open, char close) {

        for (int count = 0; i < s.length(); i++) {
            count += s.charAt(i) == open ? 1 : 0;
            count -= s.charAt(i) == close ? 1 : 0;
            if (count < 0) {
                int init = j;
                for (; j <= i; j++) {
                    if (s.charAt(j) == close && (j == init || s.charAt(j) != s.charAt(j - 1))) {
                        dfs(rst, s.substring(0, j) + s.substring(j + 1), i, j, open, close);
                    }
                }
                return;
            }
        }
        
        String reversed = new StringBuffer(s).reverse().toString();
        if (open == '(') {
            dfs(rst, reversed, 0, 0, close, open);
        } else {
            rst.add(reversed);
        }
    }
private void sample_funcname ( List < String > rst , String s , int i , int j , char open , char close ) {
  for ( int count = 0 ;
  i < s . length ( ) ;
  i ++ ) {
    count += s . charAt ( i ) == open ? 1 : 0 ;
    count -= s . charAt ( i ) == close ? 1 : 0 ;
    if ( count < 0 ) {
      int init = j ;
      for ( ;
      j <= i ;
      j ++ ) {
        if ( s . charAt ( j ) == close && ( j == init || s . charAt ( j ) != s . charAt ( j - 1 ) ) ) {
          dfs ( rst , s . substring ( 0 , j ) + s . substring ( j + 1 ) , i , j , open , close ) ;
        }
      }
      return ;
    }
  }
  String reversed = new StringBuffer ( s ) . reverse ( ) . toString ( ) ;
  if ( open == '(' ) {
    dfs ( rst , reversed , 0 , 0 , close , open ) ;
  }
  else {
    rst . add ( reversed ) ;
  }
}
