File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ """
3
+ 1. ์คํ์ ํ์ฉํ ๋ถ๊ธฐ ์ฒ๋ฆฌ
4
+ ์ฌ๋ ๊ดํธ์ผ ๋๋ ์คํ์ ๋ฌด์กฐ๊ฑด ๋ฃ์ด์ค๋ค.
5
+ ๋ซ๋ ๊ดํธ์ผ ๋๋ ๋, ์ค, ์ ๊ดํธ์ ๋ง์ถฐ์ ๋ถ๊ธฐ๋ฅผ ํด์ค์ผ ํ๋ค.
6
+ ์คํ์ด ์๊ณ , ์คํ์ ๋ง์ง๋ง์ด ํด๋น ๊ดํธ์ ์ฌ๋ ๊ดํธ์ด๋ฉด ๋นผ๋ด์ค๋ค.
7
+ ์ด์ธ๋ ๋ซํ ๊ดํธ๊ฐ ๋จผ์ ๋์ค๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ False๋ฅผ ๋ฐํํด์ค๋ค.
8
+ ์ ํ์ ์ธ ์คํ ๋ฌธ์ ๋ก O(n)์ ์๊ฐ๋ณต์ก๋๋ฅผ ๊ฐ์ง๋ค.
9
+ """
10
+ def isValid (self , s : str ) -> bool :
11
+ stack = []
12
+ for word in s :
13
+ if word == "(" or word == "{" or word == "[" :
14
+ stack .append (word )
15
+ elif stack and word == ")" and stack [- 1 ] == "(" :
16
+ stack .pop ()
17
+ elif stack and word == "]" and stack [- 1 ] == "[" :
18
+ stack .pop ()
19
+ elif stack and word == "}" and stack [- 1 ] == "{" :
20
+ stack .pop ()
21
+ else :
22
+ return False
23
+ return True if not stack else False
You canโt perform that action at this time.
0 commit comments