/******************************************************************* Copyright(c) 2016, Harry He All rights reserved.
Distributed under the BSD license. (See accompanying file LICENSE.txt at https://github.com/zhedahht/CodingInterviewChinese2/blob/master/LICENSE.txt) *******************************************************************/
#include <cstdio>
bool Find(int* matrix, int rows, int columns, int number) { bool found = false;
if (matrix != nullptr && rows > 0 && columns > 0) { int row = 0; int column = columns - 1; while (row < rows && column >= 0) { if (matrix[row * columns + column] == number) { found = true; break; } else if (matrix[row * columns + column] > number) --column; else ++row; } }
近期评论