add initial data

This commit is contained in:
timeshifter committed 2026-09-04 15:56:45 +02:00
1 parent 048a82b101
commit 51d935d06b
66 files changed
+1329

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "leetcode"
version = "0.1.0"
@@ -0,0 +1,6 @@
[package]
name = "leetcode"
version = "0.1.0"
edition = "2024"
[dependencies]
@@ -0,0 +1,37 @@
fn main() {
println!("Hello, world!");
}
pub fn max_area(height: Vec<i32>) -> i32 {
let mut best = 0;
let mut left = 0;
let mut right = height.len() - 1;
while left != right {
let area = height[left].min(height[right]) * (right - left) as i32;
best = best.max(area);
if height[left] < height[right] {
left += 1;
} else {
right -= 1;
}
}
best
}
#[cfg(test)]
mod tests {
use crate::max_area;
#[test]
fn test_1() {
assert_eq!(max_area(vec![1, 8, 6, 2, 5, 4, 8, 3, 7]), 49);
}
#[test]
fn test_2() {
assert_eq!(max_area(vec![1, 1]), 1);
}
}