Skip to content

Commit 83f538a

Browse files
committed
Add explanation for "Valid parentheses" problem.
1 parent 065a79d commit 83f538a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Constraints:
3+
1. n == height.length
4+
2. 2 <= n <= 10^5
5+
3. 0 <= height[i] <= 10^4
6+
7+
Time Complexity:
8+
-
9+
10+
Space Complexity:
11+
-
12+
"""

โ€Žvalid-parentheses/KwonNayeon.pyโ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
Space Complexity: O(n)
1111
- ์ตœ์•…์˜ ๊ฒฝ์šฐ ๋ชจ๋“  ๋ฌธ์ž๊ฐ€ ์—ฌ๋Š” ๊ด„ํ˜ธ์ผ ๋•Œ ์Šคํƒ์— ๋ชจ๋‘ ์ €์žฅ
1212
- ๋”ฐ๋ผ์„œ ์ž…๋ ฅ ํฌ๊ธฐ์— ๋น„๋ก€ํ•˜๋Š” O(n) ๊ณต๊ฐ„ ํ•„์š”
13+
14+
ํ’€์ด๋ฐฉ๋ฒ•:
15+
1. ์Šคํƒ์„ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Š” ๊ด„ํ˜ธ('(', '{', '[')๋ฅผ ์ €์žฅ
16+
2. Dictionary๋ฅผ ์‚ฌ์šฉํ•ด ๋‹ซ๋Š” ๊ด„ํ˜ธ์™€ ์—ฌ๋Š” ๊ด„ํ˜ธ์˜ ์Œ์„ O(1)๋กœ ๋งค์นญ
17+
3. ๋ฌธ์ž์—ด์„ ์ˆœํšŒํ•˜๋ฉด์„œ:
18+
- ์—ฌ๋Š” ๊ด„ํ˜ธ๋Š” ์Šคํƒ์— ์ถ”๊ฐ€
19+
- ๋‹ซ๋Š” ๊ด„ํ˜ธ๊ฐ€ ๋‚˜์˜ค๋ฉด:
20+
a) ์Šคํƒ์ด ๋น„์–ด์žˆ๊ฑฐ๋‚˜
21+
b) ์Šคํƒ ์ตœ์ƒ๋‹จ์˜ ๊ด„ํ˜ธ๊ฐ€ ํ˜„์žฌ ๋‹ซ๋Š” ๊ด„ํ˜ธ์™€ ๋งค์นญ๋˜์ง€ ์•Š์œผ๋ฉด
22+
-> ์ž˜๋ชป๋œ ๊ด„ํ˜ธ ๋ฌธ์ž์—ด
23+
- ๋งค์นญ๋˜๋Š” ๊ฒฝ์šฐ ์Šคํƒ์—์„œ pop
24+
4. ๋ชจ๋“  ์ˆœํšŒ๊ฐ€ ๋๋‚œ ํ›„ ์Šคํƒ์ด ๋น„์–ด์žˆ์–ด์•ผ ์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ ๋ฌธ์ž์—ด
1325
"""
1426
class Solution:
1527
def isValid(self, s: str) -> bool:

0 commit comments

Comments
ย (0)