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
Выход
истина
Ожидаемыйfalse
это вопрос о 2d-массиве и я застрял при отправке кода: [code]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 }