File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed
solution/0200-0299/0240.Search a 2D Matrix II Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,29 @@ public class Solution {
181
181
}
182
182
```
183
183
184
+ ### ** Rust**
185
+
186
+ ``` rust
187
+ use std :: cmp :: Ordering ;
188
+
189
+ impl Solution {
190
+ pub fn search_matrix (matrix : Vec <Vec <i32 >>, target : i32 ) -> bool {
191
+ let m = matrix . len ();
192
+ let n = matrix [0 ]. len ();
193
+ let mut i = 0 ;
194
+ let mut j = n ;
195
+ while i < m && j > 0 {
196
+ match target . cmp (& matrix [i ][j - 1 ]) {
197
+ Ordering :: Less => j -= 1 ,
198
+ Ordering :: Greater => i += 1 ,
199
+ Ordering :: Equal => return true ,
200
+ }
201
+ }
202
+ false
203
+ }
204
+ }
205
+ ```
206
+
184
207
### ** ...**
185
208
186
209
```
Original file line number Diff line number Diff line change @@ -169,6 +169,29 @@ public class Solution {
169
169
}
170
170
```
171
171
172
+ ### ** Rust**
173
+
174
+ ``` rust
175
+ use std :: cmp :: Ordering ;
176
+
177
+ impl Solution {
178
+ pub fn search_matrix (matrix : Vec <Vec <i32 >>, target : i32 ) -> bool {
179
+ let m = matrix . len ();
180
+ let n = matrix [0 ]. len ();
181
+ let mut i = 0 ;
182
+ let mut j = n ;
183
+ while i < m && j > 0 {
184
+ match target . cmp (& matrix [i ][j - 1 ]) {
185
+ Ordering :: Less => j -= 1 ,
186
+ Ordering :: Greater => i += 1 ,
187
+ Ordering :: Equal => return true ,
188
+ }
189
+ }
190
+ false
191
+ }
192
+ }
193
+ ```
194
+
172
195
### ** ...**
173
196
174
197
```
Original file line number Diff line number Diff line change
1
+ use std:: cmp:: Ordering ;
2
+
3
+ impl Solution {
4
+ pub fn search_matrix ( matrix : Vec < Vec < i32 > > , target : i32 ) -> bool {
5
+ let m = matrix. len ( ) ;
6
+ let n = matrix[ 0 ] . len ( ) ;
7
+ let mut i = 0 ;
8
+ let mut j = n;
9
+ while i < m && j > 0 {
10
+ match target. cmp ( & matrix[ i] [ j - 1 ] ) {
11
+ Ordering :: Less => j -= 1 ,
12
+ Ordering :: Greater => i += 1 ,
13
+ Ordering :: Equal => return true ,
14
+ }
15
+ }
16
+ false
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments