240. Search a 2D Matrix II
Question
Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:
- Integers in each row are sorted in ascending from left to right.
- Integers in each column are sorted in ascending from top to bottom.
Solution
将起始点设置为第一行的最后一列。
如果搜寻目标大于该点则向下搜索。
如果搜寻目标小于该点则向左搜索。
Code
1 | class Solution { |
240. Search a 2D Matrix II
https://xuanhe95.github.io/2022/04/18/240-Search-a-2D-Matrix-II/