当前位置:网站首页>【leetcode】74. Search 2D matrix
【leetcode】74. Search 2D matrix
2022-07-02 03:52:00 【Chinese fir sauce_】
subject :
74. Search for a two-dimensional matrix
Write an efficient algorithm to judge m x n Matrix , Is there a target value . The matrix has the following characteristics :
The integers in each row are arranged in ascending order from left to right .
The first integer in each row is greater than the last integer in the previous row .
Example 1:
Input :matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
Output :true
Example 2:
Input :matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
Output :false
Tips :
m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-104 <= matrix[i][j], target <= 104
Ideas :
Start at the top right .
Time complexity :O(log n)
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int m = matrix.length;
int n = matrix[0].length;
for(int i = 0,j = n - 1; i < m && j >= 0;){
if(matrix[i][j] == target) return true;
else if (target > matrix[i][j]) i++;
else j--;
}
return false;
}
}
边栏推荐
- It took me only 3 months to jump out of the comfort zone and become an automated test engineer for 5 years
- Blue Bridge Cup single chip microcomputer sixth temperature recorder
- [untitled] basic operation of raspberry pie (2)
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验2 蜂鸣器实验(学习笔记)
- 蓝桥杯单片机省赛第十二届第二场
- The 7th Blue Bridge Cup single chip microcomputer provincial competition
- 数据库文件逻辑结构形式指的是什么
- A thorough understanding of the development of scorecards - the determination of Y (Vintage analysis, rolling rate analysis, etc.)
- 高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
- leetcode-1380. Lucky number in matrix
猜你喜欢

First acquaintance with string+ simple usage (II)

The 7th Blue Bridge Cup single chip microcomputer provincial competition

高性能 低功耗Cortex-A53核心板 | i.MX8M Mini

树莓派GPIO引脚控制红绿灯与轰鸣器

Analyse de 43 cas de réseaux neuronaux MATLAB: Chapitre 42 opérations parallèles et réseaux neuronaux - - opérations parallèles de réseaux neuronaux basées sur CPU / GPU

How should the team choose the feature branch development mode or trunk development mode?

蓝桥杯单片机省赛第十届

【DesignMode】建造者模式(Builder model)

MD5 of Oracle
![[mv-3d] - multi view 3D target detection network](/img/aa/741b36ead2dfaa5a165401b8d657b7.jpg)
[mv-3d] - multi view 3D target detection network
随机推荐
Unity脚本的基础语法(6)-特定文件夹
MD5 of Oracle
How about Ping An lifetime cancer insurance?
SQL: common SQL commands
How should the team choose the feature branch development mode or trunk development mode?
Object oriented thinking
蓝桥杯单片机省赛第七届
It took me only 3 months to jump out of the comfort zone and become an automated test engineer for 5 years
【DesignMode】原型模式(prototype pattern)
向数据库中存入数组数据,代码出错怎么解决
What do you know about stock selling skills and principles
[punch in] flip the string (simple)
【无线图传】基于FPGA的简易无线图像传输系统verilog开发,matlab辅助验证
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板,老板也有建设积分和捣乱积分, 排好队后,所有
Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
Influence of air resistance on the trajectory of table tennis
Xlwings drawing
The 10th Blue Bridge Cup single chip microcomputer provincial competition
Welcome the winter vacation multi school league game 2 partial solution (B, C, D, F, G, H)
Visual slam Lecture 3 -- Lie groups and Lie Algebras