240. Search a 2D Matrix II Medium

@problem@discussion
#Array#Binary Search#Divide and Conquer#Matrix



1/**
2 * [240] Search a 2D Matrix II
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 in ascending from left to right.
7 * 	Integers in each column are sorted in ascending from top to bottom.
8 * 
9 *  
10 * Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/24/searchgrid2.jpg" style="width: 300px; height: 300px;" />
12 * Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5
13 * Output: true
14 * 
15 * Example 2:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/24/searchgrid.jpg" style="width: 300px; height: 300px;" />
17 * Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20
18 * Output: false
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	m == matrix.length
24 * 	n == matrix[i].length
25 * 	1 <= n, m <= 300
26 * 	-10^9 <= matrix[i][j] <= 10^9
27 * 	All the integers in each row are sorted in ascending order.
28 * 	All the integers in each column are sorted in ascending order.
29 * 	-10^9 <= target <= 10^9
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/search-a-2d-matrix-ii/
35// discuss: https://leetcode.com/problems/search-a-2d-matrix-ii/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn search_matrix(matrix: Vec<Vec<i32>>, target: i32) -> bool {
41        false
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_240() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.