题目描述
在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
示例1
输入
7,[[1,2,8,9],[2,4,9,12],[4,7,10,13],[6,8,11,15]]
返回值
true
思路:
大水题,双重for循环暴力即可
class Solution { public: bool Find(int target, vector<vector<int> > array) { int len1 = array.size(); int len2 = array[0].size(); for(int i=0;i<len1;i++) { for(int j=0;j<len2;j++) { if(target == array[i][j]) { return true; } } } return false; } };