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 9468c3d commit f1ff0efCopy full SHA for f1ff0ef
container-with-most-water/YeomChaeeun.ts
@@ -0,0 +1,33 @@
1
+/**
2
+ * 배열의 두개의 높이를 가지고 최대 용량을 구하기
3
+ * 알고리즘 복잡도
4
+ * - 시간 복잡도: O(n)
5
+ * - 공간 복잡도: O(1)
6
+ * @param height
7
+ */
8
+function maxArea(height: number[]): number {
9
+ // end - start * min(height[start], height[end])가 큰 것
10
+
11
+ // 8 - 0 * min(1, 7) = 8
12
+ // 8 - 1 * min(8, 7) = 49
13
+ // 7 - 1 * min(8, 3) = 18
14
+ // 6 - 1 * min(8, 8) = 40
15
+ // ...
16
17
+ let s = 0
18
+ let e = height.length - 1
19
+ let curr = 0
20
+ let max = 0
21
22
+ while(s < e) {
23
+ curr = (e - s) * Math.min(height[s], height[e])
24
+ max = Math.max(curr, max)
25
+ if(height[s] < height[e]){
26
+ s += 1
27
+ } else {
28
+ e -= 1
29
+ }
30
31
32
+ return max
33
+}
0 commit comments