Skip to content

Commit 4158189

Browse files
authored
Create yeonguchoe.cs
1 parent afecf62 commit 4158189

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
public class Solution {
4+
public int MaxArea(int[] height) {
5+
int currentMax = int.MinValue;
6+
int leftPtr = 0;
7+
int rightPtr = height.Length - 1;
8+
9+
while (leftPtr < rightPtr) {
10+
int currentAmount = (rightPtr - leftPtr) * Math.Min(height[leftPtr], height[rightPtr]);
11+
currentMax = Math.Max(currentMax, currentAmount);
12+
13+
if (height[leftPtr] < height[rightPtr]) {
14+
leftPtr++;
15+
} else {
16+
rightPtr--;
17+
}
18+
}
19+
20+
return currentMax;
21+
}
22+
}

0 commit comments

Comments
 (0)