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 1fc44b4

Browse files
committed
feat: add rust solution to lc problems: No.3025,3027
1 parent e0dbf9b commit 1fc44b4

File tree

7 files changed

+178
-2
lines changed

7 files changed

+178
-2
lines changed

‎solution/1400-1499/1405.Longest Happy String/Solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function longestDiverseString(a: number, b: number, c: number): string {
2-
let ans = [];
2+
let ans: string[] = [];
33
let store: Array<[string, number]> = [
44
['a', a],
55
['b', b],

‎solution/3000-3099/3025.Find the Number of Ways to Place People I/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,37 @@ function numberOfPairs(points: number[][]): number {
230230
}
231231
```
232232

233+
#### Rust
234+
235+
```rust
236+
impl Solution {
237+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 {
238+
points.sort_by(|a, b| {
239+
if a[0] == b[0] {
240+
b[1].cmp(&a[1])
241+
} else {
242+
a[0].cmp(&b[0])
243+
}
244+
});
245+
246+
let n = points.len();
247+
let mut ans = 0;
248+
for i in 0..n {
249+
let y1 = points[i][1];
250+
let mut max_y = i32::MIN;
251+
for j in (i + 1)..n {
252+
let y2 = points[j][1];
253+
if max_y < y2 && y2 <= y1 {
254+
max_y = y2;
255+
ans += 1;
256+
}
257+
}
258+
}
259+
ans
260+
}
261+
}
262+
```
263+
233264
#### C#
234265

235266
```cs

‎solution/3000-3099/3025.Find the Number of Ways to Place People I/README_EN.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,37 @@ function numberOfPairs(points: number[][]): number {
225225
}
226226
```
227227

228+
#### Rust
229+
230+
```rust
231+
impl Solution {
232+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 {
233+
points.sort_by(|a, b| {
234+
if a[0] == b[0] {
235+
b[1].cmp(&a[1])
236+
} else {
237+
a[0].cmp(&b[0])
238+
}
239+
});
240+
241+
let n = points.len();
242+
let mut ans = 0;
243+
for i in 0..n {
244+
let y1 = points[i][1];
245+
let mut max_y = i32::MIN;
246+
for j in (i + 1)..n {
247+
let y2 = points[j][1];
248+
if max_y < y2 && y2 <= y1 {
249+
max_y = y2;
250+
ans += 1;
251+
}
252+
}
253+
}
254+
ans
255+
}
256+
}
257+
```
258+
228259
#### C#
229260

230261
```cs
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
impl Solution {
2+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 {
3+
points.sort_by(|a, b| {
4+
if a[0] == b[0] {
5+
b[1].cmp(&a[1])
6+
} else {
7+
a[0].cmp(&b[0])
8+
}
9+
});
10+
11+
let n = points.len();
12+
let mut ans = 0;
13+
for i in 0..n {
14+
let y1 = points[i][1];
15+
let mut max_y = i32::MIN;
16+
for j in (i + 1)..n {
17+
let y2 = points[j][1];
18+
if max_y < y2 && y2 <= y1 {
19+
max_y = y2;
20+
ans += 1;
21+
}
22+
}
23+
}
24+
ans
25+
}
26+
}

‎solution/3000-3099/3027.Find the Number of Ways to Place People II/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,37 @@ function numberOfPairs(points: number[][]): number {
219219
}
220220
```
221221

222+
#### Rust
223+
224+
```rust
225+
impl Solution {
226+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 {
227+
points.sort_by(|a, b| {
228+
if a[0] == b[0] {
229+
b[1].cmp(&a[1])
230+
} else {
231+
a[0].cmp(&b[0])
232+
}
233+
});
234+
235+
let n = points.len();
236+
let mut ans = 0;
237+
for i in 0..n {
238+
let y1 = points[i][1];
239+
let mut max_y = i32::MIN;
240+
for j in (i + 1)..n {
241+
let y2 = points[j][1];
242+
if max_y < y2 && y2 <= y1 {
243+
max_y = y2;
244+
ans += 1;
245+
}
246+
}
247+
}
248+
ans
249+
}
250+
}
251+
```
252+
222253
#### C#
223254

224255
```cs

‎solution/3000-3099/3027.Find the Number of Ways to Place People II/README_EN.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tags:
4343
<pre>
4444
<strong>Input:</strong> points = [[1,1],[2,2],[3,3]]
4545
<strong>Output:</strong> 0
46-
<strong>Explanation:</strong> There is no way to place Alice and Bob such that Alice can build a fence with Alice&#39;s position as the upper left corner and Bob&#39;s position as the lower right corner. Hence we return 0.
46+
<strong>Explanation:</strong> There is no way to place Alice and Bob such that Alice can build a fence with Alice&#39;s position as the upper left corner and Bob&#39;s position as the lower right corner. Hence we return 0.
4747
</pre>
4848

4949
<p><strong class="example">Example 2:</strong></p>
@@ -210,6 +210,37 @@ function numberOfPairs(points: number[][]): number {
210210
}
211211
```
212212

213+
#### Rust
214+
215+
```rust
216+
impl Solution {
217+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 {
218+
points.sort_by(|a, b| {
219+
if a[0] == b[0] {
220+
b[1].cmp(&a[1])
221+
} else {
222+
a[0].cmp(&b[0])
223+
}
224+
});
225+
226+
let n = points.len();
227+
let mut ans = 0;
228+
for i in 0..n {
229+
let y1 = points[i][1];
230+
let mut max_y = i32::MIN;
231+
for j in (i + 1)..n {
232+
let y2 = points[j][1];
233+
if max_y < y2 && y2 <= y1 {
234+
max_y = y2;
235+
ans += 1;
236+
}
237+
}
238+
}
239+
ans
240+
}
241+
}
242+
```
243+
213244
#### C#
214245

215246
```cs
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
impl Solution {
2+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 {
3+
points.sort_by(|a, b| {
4+
if a[0] == b[0] {
5+
b[1].cmp(&a[1])
6+
} else {
7+
a[0].cmp(&b[0])
8+
}
9+
});
10+
11+
let n = points.len();
12+
let mut ans = 0;
13+
for i in 0..n {
14+
let y1 = points[i][1];
15+
let mut max_y = i32::MIN;
16+
for j in (i + 1)..n {
17+
let y2 = points[j][1];
18+
if max_y < y2 && y2 <= y1 {
19+
max_y = y2;
20+
ans += 1;
21+
}
22+
}
23+
}
24+
ans
25+
}
26+
}

0 commit comments

Comments
(0)

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