We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cf829de commit e770311Copy full SHA for e770311
0020v2.java
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ //取自一个评论,侵删
3
+ HashMap<Character, Character> paranthesesMap = new HashMap<>();
4
+
5
+ public Solution(){
6
+ this.paranthesesMap.put('(', ')');
7
+ this.paranthesesMap.put('[', ']');
8
+ this.paranthesesMap.put('{', '}');
9
+ }
10
11
+ public boolean isValid(String s) {
12
+ Stack<Character> myStack = new Stack<Character>();
13
+ for(char c: s.toCharArray()) {
14
+ if (paranthesesMap.keySet().contains(c)) myStack.push(paranthesesMap.get(c));
15
+ else if (myStack.isEmpty() || c != myStack.pop()) return false;
16
17
+ return myStack.isEmpty();
18
19
+}
0 commit comments