File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ [๋ฌธ์ ํ์ด]
3
+ - ์ด๋ฆฐ ๊ดํธ์ ๋ํ ์คํ์ ์์ผ๋ฉด ์ด๋จ๊น?
4
+ - ๋ซ๋ ๊ดํธ๊ฐ ์ค์ํ๋๊น ๋ซํ๋๊ฑธ ์์๋ณด์.
5
+ time: O(N), space: O(N)
6
+
7
+ [ํ๊ณ ]
8
+ ๋ถ๊ธฐ์ฒ๋ฆฌ๊ฐ ๋ณด๊ธฐ ์ซ๊ฒ ๋์ด ์๋๋ฐ Map์ผ๋ก ํ๋ฉด ์ข์๊น? ์คํ๋ ค ๊ณต๊ฐ์ ๋ ์ฐ๊ฒ ๋๋๊ฑด ์๋๊น?
9
+ ์ค๋ฌด๋ผ๋ฉด ์ธ ๊ฒ ๊ฐ๋ค.
10
+ */
11
+ class Solution {
12
+ public boolean isValid (String s ) {
13
+ Deque <Character > stack = new ArrayDeque <>();
14
+ for (char c : s .toCharArray ()) {
15
+ if (c == '(' ) {
16
+ stack .push (')' );
17
+ } else if (c == '{' ) {
18
+ stack .push ('}' );
19
+ } else if (c == '[' ) {
20
+ stack .push (']' );
21
+ } else {
22
+ if (stack .isEmpty () || stack .pop () != c ) {
23
+ return false ;
24
+ }
25
+ }
26
+ }
27
+ return stack .isEmpty ();
28
+ }
29
+ }
30
+
You canโt perform that action at this time.
0 commit comments