и я застрял при отправке кода -
Код: Выделить всё
`bool searchMatrix(vector& matrix, int target) {
//by using hit and try method and little bit of binary spice
int row=matrix.size();;
int col=matrix[0].size();
int rowIndex=0; // this like the variable start used in binary
int colIndex= col-1; // this like the variable end
while(rowIndex=0) // if it become false means all element are checked
{
int element =((matrix[rowIndex][colIndex])/2); // like mid variable;
if(element==target) // case 1
{
return true; // element found
}
else if(element>target) // case 2
{
colIndex--; // it is at left side of element
}
else
{
rowIndex++; // it is down the row where larger number are present
}
}
return false;
}`
**
Входная
матрица =[[-5]]
цель =
-2
Вывод
true
Ожидается
ложь
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-question