当前位置:网站首页>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;}}边栏推荐
- RNA修饰质谱检测|dextran-siRNA 葡聚糖化学偶联DNA/RNA|siRNA-PLGA聚乳酸-羟基乙酸共聚物修饰核糖核酸
- GalNAc-siRNA甘露糖/半乳糖修饰脱氧核糖核酸|siRNA-S-S-DSPE(RNA修饰技术介绍)
- 关于安装软件时x86 ,x64,x86_64,ARM 64, ARM 32 的选择
- The ambition of glory: "high-end civilians" in a smart world
- 小学弟问:程序员的工作是不是每天都是敲一天的代码呢?
- [GXYCTF2019]禁止套娃
- offsetwidth111[easy to understand]
- 336. 回文对
- The difference between analog, digital and switching
- A dish hold up valuations billions of mt. Pickled fish, can move beyond the edge food safety?
猜你喜欢

A dish hold up valuations billions of mt. Pickled fish, can move beyond the edge food safety?

图床软件要收费,算了我自己写一个开源免费的。

The younger brother asked: Is the work of a programmer a day’s work of code?

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

聚丙烯微孔膜的等离子体改性及DNA|有机自由基改性DNA-阳离子脂质复合体的应用

Hyaluronic acid-siRNA透明质酸修饰核糖核酸|peptide–siRNA 多肽偶连RNA/DNA核酸(齐岳PNA修饰物)
![[GXYCTF2019] ban dolls](/img/91/3f64bebd13a8b13fbb387c2acf8618.png)
[GXYCTF2019] ban dolls

常用电源符号含义分享

模拟量、数字量与开关量的区别

Safe Browser will have these hidden features that will let you play around with your browser
随机推荐
internship:利用easypoi将excel表数据导入导出
回归——岭回归
ES6用法,面试大全
双功能RGD-TAT修饰DNA纳米胶束|聚苯胺纳米线修饰DNA(PAINW/DNA)
点击返回顶部
错误解决:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255]
Kubernetes: (4) Common commands
Where is Naive Bayes "naive"?
C# 窗体与子线程数据交互
从实例学Kettle(一):获取股票行情数据
LeetCode_474_一和零
Internship: use easypoi to import and export excel table data
940. 不同的子序列 II
手写dialog弹框
JMeter usage tutorial (2)
ACM study book introduction
conda虚拟环境 | install 与 list 问题
朴素贝叶斯“朴素”在哪里?
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
荧光量子点修饰siRNA-QDs|纳米金修饰siRNA-Au(RNA修饰方式方法)