当前位置:网站首页>20220524搜索和排序:搜索二维矩阵II
20220524搜索和排序:搜索二维矩阵II
2022-08-09 02:37:00 【丿SeeYouAgain】
题目描述:编写一个高效的算法来搜索 m x n
矩阵 matrix
中的一个目标值 target
。该矩阵具有以下特性:
- 每行的元素从左到右升序排列。
- 每列的元素从上到下升序排列。
编码实现:
public boolean searchMatrix(int[][] matrix, int target) {
int row = 0,column = matrix[0].length - 1;
while (row < matrix.length && column >= 0) {
if(matrix[row][column] > target){
column--;
}else if(matrix[row][column] < target){
row++;
}else{
return true;
}
}
return false;
}
边栏推荐
猜你喜欢
gpio子系统和pinctrl子系统(上)
Jenkins配置钉钉通知
Processing Point Clouds
数字 01 Vivado2018.2安装及实操
ROS2错误:不支持OpenGL 1.5 GLRenderSystem:: ci initialiseContext在C: \ \ ws \构建……
The first lesson of HNUMSC-C language
HMS Core分析服务智能运营6.5.1版本上线
MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions
带你做接口测试从零到第一条用例 总结
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
随机推荐
Postman接口测试【官网】最新版本 安装及使用入门教程
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
18.flink Table/Sql API之 catlog
<爆>2022中文版-《海外博士申请指南-材料准备、时间线、套磁、面试及录取》免费分享
【剑指offer65】不适用加减乘除做加法
Open3D 点云曲率计算
2022年最流行的自动化测试工具有哪些?全网最全最细都在这里了
Likou Brush Question Record 5.1-----59. Spiral Matrix II
The building had been registry cluster, load balancing
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
高性能 MySQL(十二):分区表
Redis系列文章导航
“蔚来杯“2022牛客暑期多校训练营7,签到题CFGJ
ZCMU--5115: Buying Keys(C语言)
USB 触摸在竖屏时校准
VS2019编译boost_1_79,生成32位和64位静态库
【HNUMSC】C language second lecture
Financial Industry Software Testing Interview Questions (with Answers) | Getting Started Guide
最强分布式锁工具:Redisson
jmeter的websocket插件安装和使用方法