当前位置:网站首页>240. Searching 2D Matrix II
240. Searching 2D Matrix II
2022-07-29 21:25:00 【Xiao Lu wants to brush the force and deduct the question】
Article table of contents
Foreword
Write an efficient algorithm to search for a target value target in the m x n matrix matrix .The matrix has the following properties:
The elements of each row are arranged in ascending order from left to right.
The elements of each column are arranged in ascending order from top to bottom.
Source: LeetCode
Link: https://leetcode.cn/problems/search-a-2d-matrix-ii
The copyright belongs to Linking.com.For commercial reprints, please contact the official authorization, and for non-commercial reprints, please indicate the source.
Solution ideas
Classic solution: .
Start from the upper right corner
If the current number is greater than the target
Then find it from the left
If the current number is less than the target number, look down
Code
class Solution {public boolean searchMatrix(int[][] matrix, int target) {int row=0;int col=matrix[0].length-1span>;while(row<matrix.length&&col>=0){if(matrix[row][col]==target){return true;}else if(matrix[row][col]>target){col--;}else{row++;}}return false;}}边栏推荐
- 优惠券系统设计思想
- 小学弟问:程序员的工作是不是每天都是敲一天的代码呢?
- PEG-PEI共聚物/DNA复合物|甘草次酸修饰的长循环阳离子脂质体DNA复合物|解析说明
- Briefly talk about K-means clustering
- 怎么实现您的个人知识库?
- 五个供应商销售谈判策略的识别以及应对它们的方法
- 怎么实现您的个人知识库?
- 聚丙烯微孔膜的等离子体改性及DNA|有机自由基改性DNA-阳离子脂质复合体的应用
- Is it safe to use the MD5 encrypted string to store the password?Hash algorithm you have to know
- [GXYCTF2019] ban dolls
猜你喜欢

怎么实现您的个人知识库?

In the past six months, I have done those things about the automatic return of the transaction link...

双功能RGD-TAT修饰DNA纳米胶束|聚苯胺纳米线修饰DNA(PAINW/DNA)

JMeter usage tutorial (2)

GalNAc-siRNA甘露糖/半乳糖修饰脱氧核糖核酸|siRNA-S-S-DSPE(RNA修饰技术介绍)

378. 有序矩阵中第 K 小的元素

Private domain growth | Private domain members: 15 case collections from 9 major chain industries

一道菜撑起百亿估值的太二酸菜鱼,能否迈过食品安全这道坎?

sad rock
![[mathematical foundation] probability and mathematical statistics related concept learning](/img/bc/d3a246240ff7aca2b84c3766383758.png)
[mathematical foundation] probability and mathematical statistics related concept learning
随机推荐
336. 回文对
一道菜撑起百亿估值的太二酸菜鱼,能否迈过食品安全这道坎?
Unity determines whether a string can be converted to float type
R language for airbnb data nlp text mining, geography, word cloud visualization, regression GAM model, cross-validation analysis
Omni-channel e-commerce | How can well-known domestic cosmeceuticals seize the opportunity to achieve rapid growth?
七个易犯的 IT 管理错误—以及如何避免
uri与url的区别简单理解(uri和url有什么区别)
json-c实现json和结构体之间的相互转换
五个供应商销售谈判策略的识别以及应对它们的方法
leetcode:952. 按公因数计算最大组件大小【并查集】
探索创客教育在线管理实施体系
微博账号奇葩逻辑产品设计
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
Durable rules(持久规则引擎) 学习小记
Summary of scratch learning related materials
OAuth,JWT ,OIDC你们搞得我好乱啊
进程间六种通信方式
[GXYCTF2019] ban dolls
图床软件要收费,算了我自己写一个开源免费的。
【无标题】