74. Search a 2D Matrix Medium
1/**
2 * [74] Search a 2D Matrix
3 *
4 * Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:
5 *
6 * Integers in each row are sorted from left to right.
7 * The first integer of each row is greater than the last integer of the previous row.
8 *
9 *
10 * Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2020/10/05/mat.jpg" style="width: 322px; height: 242px;" />
12 * Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
13 * Output: true
14 *
15 * Example 2:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2020/10/05/mat2.jpg" style="width: 322px; height: 242px;" />
17 * Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
18 * Output: false
19 *
20 *
21 * Constraints:
22 *
23 * m == matrix.length
24 * n == matrix[i].length
25 * 1 <= m, n <= 100
26 * -10^4 <= matrix[i][j], target <= 10^4
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/search-a-2d-matrix/
32// discuss: https://leetcode.com/problems/search-a-2d-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn search_matrix(matrix: Vec<Vec<i32>>, target: i32) -> bool {
38 false
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_74() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.