当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
不会吧!不会吧!居然还有人不知道重绘以及回流
企业从云服务的承诺支出中获得最大收益的四种方法
Tricore架构上的调试案例
[ANT]apache ant 安装说明
Working subtotal rtcp length and network byte order
Likou Brush Question Record 6.1-----203. Remove linked list elements
2.1-----27. Remove elements
Jenkins environment deployment, (packaging, publishing, deployment, automated testing)
历史最全DL相关书籍、课程、视频、论文、数据集、会议、框架和工具整理分享
高性能 MySQL(十二):分区表
随机推荐
Recently, I have seen a lot of people who want to study by themselves or enroll in classes but don’t know how to choose. I will tell you about it today.
YOLOV1详解——Pytorch版
MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions
Line segment tree of knowledge
2022 Eye Health Brand Franchise Exhibition, Beijing Vision Care Exhibition, China Ophthalmology Technology Summit
Yii2开启 Schema 缓存
最强分布式锁工具:Redisson
【Redis】主从复制的核心原理
通过安装VNC服务器x11vnc(或vnc4server)和配置x11vnc.service实现远程通过VNC-Viewer访问VNC服务器。
The most fierce "employee" in history, madly complaining about the billionaire boss Xiao Zha: So rich, he always wears the same clothes!
高性能 MySQL(十二):分区表
1160. 拼写单词
企业从云服务的承诺支出中获得最大收益的四种方法
连接数据库且在网页运行的RDLC
企业面临的五大数据安全挑战
危化企业双预防机制数字化建设工作要求
带你做接口测试从零到第一条用例 总结
Likou Brush Question Record 5.1-----59. Spiral Matrix II
[TensorRT] 对UNet进行推理加速
1261. 在受污染的二叉树中查找元素