Skip to content

Commit 4de554e

Browse files
authored
Update ValidParentheses.java
1 parent 04e1701 commit 4de554e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

ValidParentheses.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringStack;
2-
31
import java.util.HashMap;
42
import java.util.Map;
53
import java.util.Stack;
@@ -23,17 +21,17 @@ public static void main(String[] args){
2321
}
2422

2523
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('[', ']');
3129
for(char c : s.toCharArray()){
32-
if(matchingParentheses.containsKey(c)) {
30+
if(map.containsKey(c)) {
3331
openingCharsStack.push(c);
3432
}
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)) {
3735
return false;
3836
}
3937
}

0 commit comments

Comments
 (0)