问:在一个杨氏矩阵中查找某个数
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int Ayue(int arr[3][3], int k, int row, int col) { int x = 0; int y = col - 1; while (x < row && y >= 0) { if (arr[x][y] > k) y--; else if (arr[x][y] < k) x++; else return 1; } } int main() { int arr[3][3] = { {1,2,3},{4,5,6},{7,8,9} }; int a = 0; printf("请输入您想要查找的数字:"); scanf("%d", &a); int ret = Ayue(arr, a, 3, 3); if (ret == 1) printf("找到了!"); else printf("没有找到"); return 0; }
,时间复杂度要小于O(N)
标签:arr,int,代码,练习,37,ret,else,printf,row From: https://www.cnblogs.com/ayue6/p/17787952.html