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 2e944b3 commit 4102d1aCopy full SHA for 4102d1a
valid-parentheses/jinhyungrhee.java
@@ -0,0 +1,27 @@
1
+import java.util.*;
2
+class Solution {
3
+ public boolean isValid(String s) {
4
+
5
+ Deque<Character> stack = new ArrayDeque<>();
6
+ Map<Character, Character> table = new HashMap<>();
7
+ table.put(')', '(');
8
+ table.put(']', '[');
9
+ table.put('}', '{');
10
11
+ for (int i = 0; i < s.length(); i++) {
12
+ if (table.containsKey(s.charAt(i))) {
13
14
+ if ((table.get(s.charAt(i))).equals(stack.peek())) {
15
+ stack.pop();
16
+ } else {
17
+ stack.push(s.charAt(i));
18
+ }
19
20
21
22
23
24
25
+ return stack.isEmpty();
26
27
+}
0 commit comments