【面试题】剑指offer 2
来源:互联网 发布:南京银行 总行 知乎 编辑:程序博客网 时间:2024/06/05 03:18
题目:在一个二维数组中,每一行从左往右,每一列从上到下都是递增的,给任意值在数组只能查找该数
#include<stdio.h>#include<string.h>#include<stdlib.h>int getsize(int data[]){return sizeof(data);}bool Find(int* matrix,int rows,int cols,int num){bool found=false;if(matrix!=NULL&&rows>0&&cols>0){int row=0;int col=cols-1;while(row<rows&&col>0){if(matrix[row*cols+col]==num)//row*cols+col{found=true;break;}else if (matrix[row*cols+col]>num)//右上角大于num,列左移{--col;}else//右上角小于num,行下移{++row;}}return found;}}//int main()//{//int data1[]={1,2,3,4,5};//int size1=sizeof(data1);//int *data2=data1;//int size2=sizeof(data2);//int size3=getsize(data1);//printf("%d;%d;%d\n",size1,size2,size3);//system("pause");//return 0;//}int main(){int matrix[]={1,2,3,9,2,4,9,12,4,7,10,13,6,8,11,15};int ret=Find(matrix,4,4,10);printf("%d\n",ret);system("pause");return 0;}
0 0
- 剑指offer 面试题2
- 【面试题】剑指offer 2
- 剑指offer 面试题
- 剑指offer面试题
- 《剑指offer》面试题3(2)
- 剑指Offer面试题2:替换空格
- 剑指offer面试题总结
- 剑指offer面试题06
- 剑指offer面试题 04
- 剑指offer 面试题07
- 剑指offer面试题08
- 剑指offer面试题42
- 剑指offer面试题1
- 剑指offer面试题3
- 剑指offer面试题4
- 剑指offer面试题5
- 剑指offer面试题6
- 剑指offer面试题7
- git简易使用指南
- 史上最全使用Nexus搭建Maven服务器详细配置
- 理解Java中字符流与字节流的区别
- Floyd有向图的传递闭包-UVA
- 四步轻松搭建NAT服务器
- 【面试题】剑指offer 2
- 嵌入式编程中关于const,static,extern,volatile的用法
- win7下 caffe python接口配置 import caffe时报错,ImportError: No module named google.protobuf.internal
- 部署xhprof监控php效率(linux版本)
- Directx11教程四十之加载OBJ模型
- 阿里云服务器 centos7 搭建FTP服务器
- 【Python】numpy 中的 copy 问题详解
- CODEVS 1039 数的划分
- cookie