博文中会简要介绍Leetcode P0074题目分析及解题思路。
“Search a 2D Matrix”是一道比较有意思的题目,考察的重点在于灵活运用二分查找算法。
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. Example 1:
分成两部分来二分查找,对第一列二分查找,然后对指定行二分查找。
以下是Java的题解代码实现。
以下是C++的题解代码实现。