亲宝软件园·资讯

展开

剑指offer-4

松饼s 人气:0
#include <stdio.h>

bool Find(int* matrix, int rows, int columns, int number)
{
    int i = 0;
    int j = columns-1;
    while(i<rows && j>=0)
    {
        if(matrix[i*columns+j] == number)
        {
            return true;
        }
        else if(matrix[i*columns+j]>number)
            j--;
        else
            i++;
    }
    return false;
    
}
int main()
{
    int matrix[][4] = {{1, 2, 8, 9}, {2, 4, 9, 12}, {4, 7, 10, 13}, {6, 8, 11, 15}};
    int number = 4;
    bool  result = Find((int*)matrix, 4, 4, number);
    printf("%d\n",result);
}

 

加载全部内容

相关教程
猜你喜欢
用户评论