aboutsummaryrefslogtreecommitdiff
path: root/most_water.cpp
blob: 89d4e19b94167b61a150e4740b164b18ae8fc4f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
  int maxArea(vector<int> &height) {
    int start = 0, max = 0, end = height.size() - 1;
    while (start < end) {
      int x = end - start;
      int y = height[start] > height[end] ? height[end] : height[start];
      max = (x * y) > max ? (x * y) : max;
      if (height[start] > height[end])
        end--;
      else
        start++;
    }
    return max;
  }
};

int main() {}