Skip to content

Commit bdb3a4b

Browse files
authored
Create offer_4
1 parent 5675a56 commit bdb3a4b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

offer_4

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//面试题4:二维数组的查找
2+
bool Find(int* matrix, int rows,int columns,int number)
3+
{
4+
bool found=false;
5+
if(matrix !=nullptr && rows>0 && colunms>0)
6+
{
7+
int row=0;
8+
int column=columns-1;
9+
while(row<rows && colunm>=0)
10+
{
11+
if(matrix[row*columns+column] == number){
12+
found=true;
13+
break;
14+
}else if(matrix[row*columns+column] > number){
15+
--column;
16+
}else{
17+
++row;
18+
}
19+
}
20+
}
21+
return found;
22+
}
23+
24+
25+
26+
27+

0 commit comments

Comments
 (0)