bool findNumberIn2DArray(int** matrix, int matrixSize, int* matrixColSize, int target){
if((matrixSize==0) ||(matrixColSize[0]==0))
return false;
bool find(int arr[],int size, int x){
for(int i =0; i<size; i++){
if(arr[i] == x)
return true;
}
return false;
}
bool findinside(int up,int down, int left, int right, int x){
if(down == up){
int new1[right-left+1];
for(int i = 0; i<right-left+1; i++){
new1[i] = matrix[up][left +i];
}
return find(new1, right-left+1, x);
}
if(left == right){
int new2[down-up+1];
for(int i = 0; i<down-up+1; i++){
new2[i] = matrix[up+i][left];
}
return find(new2, down-up+1, x);
}
if(x<matrix[up][left])
return false;
if(x>matrix[down][right])
return false;
bool ans = findinside(up,(up+down)/2,left, (left+right)/2,target)||\
findinside((up+down)/2+1,down,left, (left+right)/2,target)||\
findinside(up,(up+down)/2,(left+right)/2+1,right ,target)||\
findinside((up+down)/2+1,down,(left+right)/2+1,right,target );
return ans;
}
return findinside(0,matrixSize-1,0,matrixColSize[0]-1,target);
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步