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 7a6e3ad

Browse files
authored
feat: add rust solution to lc problem: No.2643 (#1129)
1 parent 463b37c commit 7a6e3ad

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

‎solution/2600-2699/2643.Row With Maximum Ones/README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ function rowAndMaximumOnes(mat: number[][]): number[] {
158158
}
159159
```
160160

161+
### **Rust**
162+
163+
```rust
164+
impl Solution {
165+
pub fn row_and_maximum_ones(mat: Vec<Vec<i32>>) -> Vec<i32> {
166+
let mut ans = vec![0, 0];
167+
168+
for (i, row) in mat.iter().enumerate() {
169+
let cnt = row.iter().filter(|&v| *v == 1).count() as i32;
170+
if ans[1] < cnt {
171+
ans[0] = i as i32;
172+
ans[1] = cnt;
173+
}
174+
}
175+
176+
ans
177+
}
178+
}
179+
```
180+
161181
### **...**
162182

163183
```

‎solution/2600-2699/2643.Row With Maximum Ones/README_EN.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ function rowAndMaximumOnes(mat: number[][]): number[] {
143143
}
144144
```
145145

146+
### **Rust**
147+
148+
```rust
149+
impl Solution {
150+
pub fn row_and_maximum_ones(mat: Vec<Vec<i32>>) -> Vec<i32> {
151+
let mut ans = vec![0, 0];
152+
153+
for (i, row) in mat.iter().enumerate() {
154+
let cnt = row.iter().filter(|&v| *v == 1).count() as i32;
155+
if ans[1] < cnt {
156+
ans[0] = i as i32;
157+
ans[1] = cnt;
158+
}
159+
}
160+
161+
ans
162+
}
163+
}
164+
```
165+
146166
### **...**
147167

148168
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn row_and_maximum_ones(mat: Vec<Vec<i32>>) -> Vec<i32> {
3+
let mut ans = vec![0, 0];
4+
5+
for (i, row) in mat.iter().enumerate() {
6+
let cnt = row.iter().filter(|&v| *v == 1).count() as i32;
7+
if ans[1] < cnt {
8+
ans[0] = i as i32;
9+
ans[1] = cnt;
10+
}
11+
}
12+
13+
ans
14+
}
15+
}

0 commit comments

Comments
(0)

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