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 1dfd2bf commit aa60d92Copy full SHA for aa60d92
βvalid-parentheses/hjeomdev.javaβ
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ public boolean isValid(String s) {
3
+ // μ€ν... 머리μμ λ μ€λ₯΄λ μκ°μ μλλ° μ λ¦¬κ° μλ..
4
+ // ν΄μ€ μ½μ
5
+
6
+ Map<Character, Character> parens = new HashMap<>();
7
+ parens.put('(', ')');
8
+ parens.put('{', '}');
9
+ parens.put('[', ']');
10
11
+ Stack<Character> stack = new Stack<>();
12
13
+ for(char c : s.toCharArray()) {
14
+ if (parens.containsKey(c)) {
15
+ stack.push(c);
16
+ } else {
17
+ if (stack.isEmpty() || c != parens.get(stack.pop())) {
18
+ return false;
19
+ }
20
21
22
23
+ return stack.isEmpty();
24
25
+}
0 commit comments