# [74. Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/)
# 思路
就是一个二分查找。将矩阵展开成一个很长的有序数组，下标low从0开始，下标high从`m*n - 1`开始，然后二分查找，中间下标mid对应的元素为`matrix[mid / n][mid % n]`。     
时间复杂度O(log(mn))，空间复杂度O(1)

# C++
``` C++
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        if(matrix.empty()) return false;
        int m = matrix.size(), n = matrix[0].size();
        int low = 0, high = m * n - 1;
        while(low <= high){
            int mid = (high - low) / 2 + low;
            int tmp = matrix[mid / n][mid % n];
            if(tmp == target) return true;
            if(tmp < target) low = mid + 1;
            else high = mid - 1;
        }
        return false;
    }
};
```
