Skip to content

Commit 85f48d9

Browse files
committed
solution for MaxArea task
1 parent 8987130 commit 85f48d9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

C#/LeetCodeResolves/LeetCodeResolves/LeetCodeResolves.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
6-
<StartupObject>LeetCodeResolves.IsPalindrome.Program</StartupObject>
6+
<StartupObject>LeetCodeResolves.MaxArea.Program</StartupObject>
77
</PropertyGroup>
88

99
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace LeetCodeResolves.MaxArea
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
var n = new int[] { 1, 8, 3, 4, 8, 5, 7 };
12+
var result = MaxArea(n);
13+
Console.ReadKey();
14+
}
15+
16+
static int MaxArea(int[] height)
17+
{
18+
int maxarea = 0, l = 0, r = height.Length - 1;
19+
while (l < r)
20+
{
21+
maxarea = Math.Max(maxarea, Math.Min(height[l], height[r]) * (r - l));
22+
if (height[l] < height[r])
23+
l++;
24+
else
25+
r--;
26+
}
27+
28+
return maxarea;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)