Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit db98324

Browse files
committedJul 26, 2023
docs: add algorithm description for container with most water
1 parent c21ecc7 commit db98324

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎src/medium/container_with_most_water.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ pub fn max_area(height: Vec<i32>) -> i32 {
1919
max_area
2020
}
2121

22+
/*
23+
Algorithm - Two Pointers
24+
25+
Time O(N)
26+
Space O(1)
27+
28+
1. left = 0, right = len-1
29+
2. loop while left < right
30+
3. area = (right-left) * min(height[left], height[right])
31+
4. maxArea = max(maxArea, area)
32+
5. if height[left] < height[right]
33+
6. left++
34+
7. else
35+
8. right--
36+
9. return maxArea
37+
*/
38+
2239
#[cfg(test)]
2340
mod tests {
2441
use super::*;

0 commit comments

Comments
 (0)
Please sign in to comment.