Search a 2D Matrix

须知少年凌云志,曾许人间第一流。这篇文章主要讲述Search a 2D Matrix相关的知识,希望能为你提供帮助。


Search a 2D Matrix

文章图片

Search a 2D Matrix

文章图片
Search a 2D Matrix

文章图片

bool searchMatrix(const vector< vector< int> > & matrix, int target)

int m = matrix.size(); //行
int n = matrix.front.size();

int first = 0;
int last = m*n;
while (first < last)

int mid = first + (last - first) / 2;
//确定其中矩阵中的位置
int value = https://www.songbingjia.com/android/matrix[mid / n][mid%n];
if (value =https://www.songbingjia.com/android/= target)return true;
else if (target> value)
first = mid + 1;
else
last = mid;



View Code






【Search a 2D Matrix】


    推荐阅读