-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainer With Most Water.rs
More file actions
48 lines (37 loc) · 976 Bytes
/
Container With Most Water.rs
File metadata and controls
48 lines (37 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pub struct Solution;
impl Solution{
pub fn max_area(height: Vec<i32>) -> i32 {
let mut left = 0;
let mut right = height.len() - 1;
let mut max_area = 0;
while left < right {
let h = std::cmp::min(height[left], height[right]);
let width = (right - left) as i32;
println!("data is : {}",width);
let current_area = h * width;
if current_area > max_area {
max_area = current_area;
}
if height[left] < height[right] {
left += 1;
} else {
right -= 1;
}
}
max_area
}
}
fn main() {
let height = vec![1, 8, 6, 2, 5, 4, 8, 3, 7];
let result = Solution::max_area(height);
println!("The maximum area is: {}", result);
}
// #[cfg(test)]
// mod test {
// use super::*;
// #[test]
// fn example1() {
// let height = vec![1,8,6,2,5,4,8,3,7];
// assert_eq!(Solution::max_area(height),49);
// }
// }