(一)剑指Offer之二维数组中的查找
2017-01-07 10:47
295 查看
题目描述:
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
输入描述:
array: 待查找的二维数组
target:查找的数字
输出描述:
查找到返回true,查找不到返回false
如有建议或其他问题,可随时给我们留言。或者到以下链接
https://github.com/gaobaoru/code_day
Star/Fork/Push 您的代码,开源仓库需要您的贡献。
请查看Coding 题目网址和收藏Accepted代码仓库,进行coding!!!
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
输入描述:
array: 待查找的二维数组
target:查找的数字
输出描述:
查找到返回true,查找不到返回false
class Solution { public: bool Find(vector<vector<int> > array,int target) { bool found = false; int rows = array.size(); int columns = array[0].size(); if(!array.empty() && rows > 0 && columns > 0){ int row=0; int column = columns-1; while(row < rows && column >= 0){ if(array[row][column] == target){ found = true; break; } else if(array[row][column] > target) --column; else ++row; } } return found; } };
如有建议或其他问题,可随时给我们留言。或者到以下链接
https://github.com/gaobaoru/code_day
Star/Fork/Push 您的代码,开源仓库需要您的贡献。
请查看Coding 题目网址和收藏Accepted代码仓库,进行coding!!!
相关文章推荐
- 使用XHR2或Jsonp实现跨域以及实现原理
- Fedora 25U盘启动盘的制作
- Effective Java : 方法
- JVM源码分析之FinalReference完全解读
- 搭建jQuery Mobile移动应用页面的3个相关框架文件
- JS入门
- 纯css使用transform实现同心圆导航栏菜单
- Effective Java : 枚举和注解
- 个人记录:Node 动态识别运行环境
- POJ 1274 The Perfect Stall(最大二分图匹配)
- H5 contenteditable 属性学习
- UI高级控件 (Bootstrap)
- Effective Java : 泛型
- HTML 各种宽和高的含义
- Javascript深入理解之继承与原型链
- jquery validation验证表单插件
- Angularjs 路由
- JQuery ZTree使用方法详解
- JS-12种设计模式
- codeforces754D Fedor and coupons