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.
2 parents 6e0c806 + b1f9499 commit 4b77d54Copy full SHA for 4b77d54
container-with-most-water/DaleSeo.rs
@@ -0,0 +1,20 @@
1
+// TC: O(n)
2
+// SC: O(1)
3
+impl Solution {
4
+ pub fn max_area(height: Vec<i32>) -> i32 {
5
+ let mut max_area = 0;
6
+ let (mut left, mut right) = (0, height.len() - 1);
7
+ while left < right {
8
+ let width = (right - left) as i32;
9
+ let min_height = height[left].min(height[right]);
10
+ let area = width * min_height;
11
+ max_area = max_area.max(area);
12
+ if height[left] < height[right] {
13
+ left += 1;
14
+ } else {
15
+ right -= 1;
16
+ }
17
18
+ max_area
19
20
+}
0 commit comments