leetcode-c语言-二分查找
240. 搜索二维矩阵 II
bool BinarySearch(int *nums, int len, int target) { int left = 0, right = len - 1; while (left <= right) { int mid = left + (right - left) / 2; if (nums[mid] == target) { return true; } else if (nums[mid] > target) { right = mid - 1; } else { left = mid + 1; } } return false; } bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target) { int m = matrixSize; // 行 int n = *matrixColSize; // 列 for (int i = 0; i < m; i++) { if (BinarySearch(matrix[i], n, target)) { return true; } } return false; }