/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param array int整型二维数组 * @param arrayRowLen int array数组行数 * @param arrayColLen int* array数组列数 * @return bool布尔型 */ bool Find(int target, int** array, int arrayRowLen, int* arrayColLen ) { // write code here if ((*arrayColLen) == arrayRowLen && arrayRowLen== 0) { return false; } int left = 0; int right = (*arrayColLen) - 1; int top = 0; int tail = arrayRowLen - 1; int lmid = (left + right) / 2; int rmid = (top + tail) / 2; while(left < right) { if (array[0][lmid] < target) { left = lmid + 1; lmid = (left + right) / 2; } else if(array[0][lmid] > target) { right = lmid - 1; lmid = ((left + right) / 2); } else { return true; } } if (array[0][right] > target) { right--; } while(right >= 0) { top = 0; tail = arrayRowLen - 1; rmid = (top + tail) / 2; while(top < tail) { if (array[rmid][right] < target) { top = rmid + 1; rmid = (top + tail) / 2; } else if (array[rmid][right] > target) { tail = rmid - 1; rmid = (top + tail) / 2; } else { return true; } } if (top == tail && array[top][right] == target) { return true; } if (right > 0 && array[arrayRowLen-1][right-1] < target) { return false; } right--; } return false; }