// 二维数组查找
2021-02-12 07:18
标签:main public amp mes nbsp str get names als // 二维数组查找 // 二维数组查找 标签:main public amp mes nbsp str get names als 原文地址:https://www.cnblogs.com/hg07/p/12731408.html
#include "stdafx.h"
using namespace std;
#include
#include
class Solution {
public:
bool Find(int target, vector
int rows = array.size();
int cols = array[0].size();
if (!array.empty() && rows > 0 && cols > 0)
{
int row = 0;
int col = cols - 1;
while (row = 0)
{
if (array[row][col] > target)
{
col = col - 1;
}
else if (array[row][col] {
row = row + 1;
}
else
{
return true;
}
}
}
return false;
}
};
int main()
{
int array[4][4] = {
{ 1, 2, 8, 9 },
{ 2, 4, 9, 12 },
{ 4, 7, 10, 13 },
{6,8,11,15} ,
};
vector
vector
vector
vector
vector
Solution sou;
sou.Find(7, kk);
return 1;
}
下一篇:Python实现集合Set