剑指Offer-【面试题03:二维数组中的查找】
2024-10-19 02:21:53
package com.cxz.question3; /* * 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。 * 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 * */ public class Demo3 { public static void main(String[] args) { , , , }, {, , , }, {, , , }, {, , , }}; System.)); System.)); System.)); } public static boolean find(int[][] matrix, int number) { //输入判断条件 || matrix[].length < ) { return false; } int rows = matrix.length; ].length; ; ; //判断查找的位置确保在数组内 && row < rows && col >= && col < cols) { if (matrix[row][col] == number) { return true; } else if (matrix[row][col] > number) { col--; } else { row++; } } return false; } }
最新文章
- 【转】随机函数 rand() srand() 以及seed的原理
- Android -- TextView、button方法详解(2)
- MC3190终端配置冷启动自动恢复的方法
- 循序渐进Python3(二) -- 数据类型
- hihocode 1077 : RMQ问题再临-线段树
- css中元素居中总结
- :root
- Android之ExpandableListView的属性(Group不展开)
- 数据库索引的实现原理(笔记)详细http://www.linezing.com/blog/?p=798#nav-1
- 在Laravel中使用swoole来取代nginx作为http服务器
- Java中子类能继承父类的私有属性吗?
- linux Cacti监控服务器搭建
- json 格式化的时候,日期格式化
- [Swift]LeetCode470. 用 Rand7() 实现 Rand10() | Implement Rand10() Using Rand7()
- Confluence 6 的系统配置信息的示例
- Git 设置过滤忽略的文件或文件夹(ignore file)
- Centos 安装Percona Toolkit工具集
- 1.line (线)
- GlobalMemoryStatusEx获取内存
- AngularJS 的常用特性(二)