diff --git a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md index c51e9bb67edf0..373a52f7c8ac4 100644 --- a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md +++ b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md @@ -208,6 +208,26 @@ function minRectanglesToCoverPoints(points: number[][], w: number): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn min_rectangles_to_cover_points(mut points: Vec>, w: i32) -> i32 { + points.sort_by(|a, b| a[0].cmp(&b[0])); + let mut ans = 0; + let mut x1 = -(1 << 30); + for p in points { + let x = p[0]; + if x1 + w < x { + x1 = x; + ans += 1; + } + } + ans + } +} +``` + diff --git a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md index 75c8a95b32d09..a595aa926003d 100644 --- a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md +++ b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md @@ -251,6 +251,26 @@ function minRectanglesToCoverPoints(points: number[][], w: number): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn min_rectangles_to_cover_points(mut points: Vec>, w: i32) -> i32 { + points.sort_by(|a, b| a[0].cmp(&b[0])); + let mut ans = 0; + let mut x1 = -(1 << 30); + for p in points { + let x = p[0]; + if x1 + w < x { + x1 = x; + ans += 1; + } + } + ans + } +} +``` + diff --git a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/Solution.rs b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/Solution.rs new file mode 100644 index 0000000000000..898d024b0830f --- /dev/null +++ b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/Solution.rs @@ -0,0 +1,15 @@ +impl Solution { + pub fn min_rectangles_to_cover_points(mut points: Vec>, w: i32) -> i32 { + points.sort_by(|a, b| a[0].cmp(&b[0])); + let mut ans = 0; + let mut x1 = -(1 << 30); + for p in points { + let x = p[0]; + if x1 + w < x { + x1 = x; + ans += 1; + } + } + ans + } +}