题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
int i = 0;
int j = array[0].size()-1;
while(i<array.size() && j>=0){
if(target > array[i][j]){
i++;
} else if (target < array[i][j]){
j--;
} else{
return true;
}
}
return false;
}
};
从右上或者左下去二分寻找
查看12道真题和解析