File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
solution/2600-2699/2643.Row With Maximum Ones Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff 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```
Original file line number Diff line number Diff 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```
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments