container-with-most-water 1.0.0
Container With Most Water
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

int maxArea (vector< int > &height)
 

Detailed Description

Definition at line 6 of file main.cpp.

Member Function Documentation

◆ maxArea()

int Solution::maxArea ( vector< int > &  height)
inline

Definition at line 9 of file main.cpp.

10 {
11 int left = 0;
12 int right = (int)height.size() - 1;
13 int volume = min(height[left], height[right]) * abs(right - left);
14 while (left < right)
15 {
16 // move pointer that points to lower value
17 if (height[left] < height[right])
18 left++;
19 else
20 right--;
21
22 // cout << "volume: " << volume << "; new_volume: " << new_volume << endl;
23 volume = max(volume, min(height[left], height[right]) * abs(right - left));
24 }
25 return volume;
26 }

Referenced by main().


The documentation for this class was generated from the following file: