题解 | #二维数组中的查找#
二维数组中的查找
https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
class Solution { public: bool Find(int target, vector<vector<int> > array) { if (array.size() == 0) return false; int m = array.size(), n = array[0].size(); int i = 0, j = n - 1; while (i < m && j >= 0) { // 只有i++和j--操作,估只判断i的上界和j的下界 if (target == array[i][j]) return true; else if (target < array[i][j]) { j--; } else { i++; } } return false; } };
#剑指offer#