Skip to content

Commit 623e191

Browse files
authored
Merge pull request #1417 from shinsj4653/main
[shinsj4653] Week 06 Solutions
2 parents 8c9c8bd + aa4e1b6 commit 623e191

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
- height 높이의 정수 배열
5+
6+
# Outputs
7+
- 담을 수 있는 최대 물의 양
8+
9+
# Constraints
10+
- n == height.length
11+
- 2 <= n <= 10^5
12+
- 0 <= height[i] <= 10^4
13+
14+
# Ideas
15+
- 1. 완탐
16+
결국 기둥 2개로 컨테이너 생성
17+
하지만, n은 10^5 -> 2중 for문 불가능
18+
19+
2. DP ?
20+
최대 물 양을 찾는 것이 문제 조건
21+
22+
특정 구간마다 최대 로 담을 수 있는 물의 양이 겹치는 걸 활용?
23+
height = 1, 8, 6, 2, 5, 4, 8 3 7
24+
dp[i][j]
25+
26+
dp[0][1] = 1
27+
dp[1][2] = 6
28+
dp[2][3] = 2
29+
dp[3][4] = 2
30+
dp[4][5] = 4
31+
dp[5][6] = 4
32+
dp[6][7] = 3
33+
dp[7][8] = 3
34+
35+
dp[0][2] => 0 ~ 2 중 높이 가장 작은 -> 1 * (j - i)
36+
dp[1][3] => 1 ~ 3 중 작은 2
37+
38+
=> 먼가 위 처럼 최소 높이 구하면서 점점 가로길이 늘려가는 식으로 풀면 될 것 같은데 이를 dp를 사용해서 구현하는 법을 모르곘음..
39+
40+
해설 참고
41+
3. 투포인터
42+
43+
44+
[회고]
45+
dp, 이분탐색 도 아닌 것 같다라면, 투포인터 고려해보기
46+
-> dp 로 단정지으니, 구간의 최솟값이나 물 양 중 어느 값을 저장해야하는지, 그리곶 저장한 값을 언제 어떻게 활용할건지..감이 안잡혀서 못 품
47+
48+
"""
49+
50+
51+
class Solution:
52+
def maxArea(self, height: List[int]) -> int:
53+
54+
ret = 0
55+
s, e = 0, len(height) - 1
56+
57+
while s < e:
58+
area = (e - s) * min(height[s], height[e])
59+
ret = max(ret, area)
60+
61+
if height[s] < height[e]:
62+
s += 1
63+
else:
64+
e -= 1
65+
66+
return ret
67+
68+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

spiral-matrix/shinsj4653.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

valid-parentheses/shinsj4653.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

0 commit comments

Comments
 (0)