File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change 1
- import com .sun .org .apache .xalan .internal .xsltc .compiler .util .StringStack ;
2
-
3
1
import java .util .HashMap ;
4
2
import java .util .Map ;
5
3
import java .util .Stack ;
@@ -23,17 +21,17 @@ public static void main(String[] args){
23
21
}
24
22
25
23
private static boolean isValid (String s ) {
26
- Stack <Character > openingCharsStack = new StringStack ();
27
- Map <Character , Character > matchingParentheses = new HashMap ();
28
- matchingParentheses .put ('{' , '}' );
29
- matchingParentheses .put ('(' , ')' );
30
- matchingParentheses .put ('[' , ']' );
24
+ Stack <Character > openingCharsStack = new Stack <> ();
25
+ Map <Character , Character > map = new HashMap ();
26
+ map .put ('{' , '}' );
27
+ map .put ('(' , ')' );
28
+ map .put ('[' , ']' );
31
29
for (char c : s .toCharArray ()){
32
- if (matchingParentheses .containsKey (c )) {
30
+ if (map .containsKey (c )) {
33
31
openingCharsStack .push (c );
34
32
}
35
- else if ((openingCharsStack .isEmpty () && matchingParentheses .containsValue (c ))
36
- || (!openingCharsStack .isEmpty () && matchingParentheses .get (openingCharsStack .pop ()) != c )) {
33
+ else if ((openingCharsStack .isEmpty () && map .containsValue (c ))
34
+ || (!openingCharsStack .isEmpty () && map .get (openingCharsStack .pop ()) != c )) {
37
35
return false ;
38
36
}
39
37
}
You can’t perform that action at this time.
0 commit comments