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 c083164 commit 6e422c0Copy full SHA for 6e422c0
1 file changed
container-with-most-water/sadie100.ts
@@ -0,0 +1,32 @@
1
+/*
2
+시작인덱스 start와 끝인덱스 end를 지정하고 result 변수를 갱신, start와 end를 좁혀가며 최대 result를 찾는다
3
+ - start와 end 중 더 작은 값을 옮겨가며 값을 비교.
4
+ - 둘이 겹쳐지면 리턴한다.
5
+
6
+result를 리턴
7
8
+시간복잡도 : O(N), 공간복잡도 : O(1)
9
+*/
10
11
+function maxArea(height: number[]): number {
12
+ let start = 0
13
+ let end = height.length - 1
14
+ let result = 0
15
16
+ function getAmount(startIdx: number, endIdx: number): number {
17
+ return (endIdx - startIdx) * Math.min(height[endIdx], height[startIdx])
18
+ }
19
20
+ while (start < end) {
21
+ const area = getAmount(start, end)
22
+ result = Math.max(result, area)
23
24
+ if (height[start] < height[end]) {
25
+ start += 1
26
+ } else {
27
+ end -= 1
28
29
30
31
+ return result
32
+}
0 commit comments