前言:
牛客網 c++ 劍指Offer_編程題 第一題二維數組中的查找
題目:
這個應該是很簡單的了,但是他肯定有簡單的方法,因爲他說了每一行和每一列的規律.我也沒多考慮 直接遍歷了一遍…
如果誰有好的辦法請貼出來學習一下
code:
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
for(auto i = 0; i<array.size();i++)
{
for(auto j = 0; j<array[i].size();j++)
{
if(array[i][j] == target)
return true;
}
}
return false;
}
};