Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4012ecc

Browse files
feat: add rust solution to lc problem: No.3111 (doocs#3337)
1 parent 610c75b commit 4012ecc

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

‎solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ function minRectanglesToCoverPoints(points: number[][], w: number): number {
208208
}
209209
```
210210

211+
#### Rust
212+
213+
```rust
214+
impl Solution {
215+
pub fn min_rectangles_to_cover_points(mut points: Vec<Vec<i32>>, w: i32) -> i32 {
216+
points.sort_by(|a, b| a[0].cmp(&b[0]));
217+
let mut ans = 0;
218+
let mut x1 = -(1 << 30);
219+
for p in points {
220+
let x = p[0];
221+
if x1 + w < x {
222+
x1 = x;
223+
ans += 1;
224+
}
225+
}
226+
ans
227+
}
228+
}
229+
```
230+
211231
<!-- tabs:end -->
212232

213233
<!-- solution:end -->

‎solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,26 @@ function minRectanglesToCoverPoints(points: number[][], w: number): number {
251251
}
252252
```
253253

254+
#### Rust
255+
256+
```rust
257+
impl Solution {
258+
pub fn min_rectangles_to_cover_points(mut points: Vec<Vec<i32>>, w: i32) -> i32 {
259+
points.sort_by(|a, b| a[0].cmp(&b[0]));
260+
let mut ans = 0;
261+
let mut x1 = -(1 << 30);
262+
for p in points {
263+
let x = p[0];
264+
if x1 + w < x {
265+
x1 = x;
266+
ans += 1;
267+
}
268+
}
269+
ans
270+
}
271+
}
272+
```
273+
254274
<!-- tabs:end -->
255275

256276
<!-- solution:end -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn min_rectangles_to_cover_points(mut points: Vec<Vec<i32>>, w: i32) -> i32 {
3+
points.sort_by(|a, b| a[0].cmp(&b[0]));
4+
let mut ans = 0;
5+
let mut x1 = -(1 << 30);
6+
for p in points {
7+
let x = p[0];
8+
if x1 + w < x {
9+
x1 = x;
10+
ans += 1;
11+
}
12+
}
13+
ans
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /