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 612c32f

Browse files
solve: 74. Search a 2D Matrix in rust
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent 6566514 commit 612c32f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
impl Solution {
2+
pub fn search_matrix(matrix: Vec<Vec<i32>>, target: i32) -> bool {
3+
let (mut rows, mut cols) = (0, matrix[0].len() - 1);
4+
5+
while rows < matrix.len() && cols > 0 {
6+
if matrix[rows][cols] == target {
7+
return true;
8+
} else if matrix[rows][cols] > target {
9+
cols -= 1;
10+
} else {
11+
rows += 1;
12+
}
13+
}
14+
15+
false
16+
}
17+
}

0 commit comments

Comments
(0)

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