当前位置:网站首页>【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;
}
}
边栏推荐
- 蓝桥杯单片机省赛第十届
- The first practical project of software tester: web side (video tutorial + document + use case library)
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- SQL:常用的 SQL 命令
- 近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
- [personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
- 一文彻底理解评分卡开发中——Y的确定(Vintage分析、滚动率分析等)
- 0基础如何学习自动化测试?按照这7步一步一步来学习就成功了
- 【无线图传】基于FPGA的简易无线图像传输系统verilog开发,matlab辅助验证
- A thorough understanding of the development of scorecards - the determination of Y (Vintage analysis, rolling rate analysis, etc.)
猜你喜欢

傅里叶级数

The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup

The 5th Blue Bridge Cup single chip microcomputer provincial competition

Lost a few hairs, and finally learned - graph traversal -dfs and BFS

Unity脚本的基础语法(6)-特定文件夹

The first game of the 12th Blue Bridge Cup single chip microcomputer provincial competition

C语言:逻辑运算和判断选择结构例题

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

High performance and low power cortex-a53 core board | i.mx8m Mini

The 6th Blue Bridge Cup single chip microcomputer provincial competition
随机推荐
Monkey测试
VS2010插件NuGet
Pandora IOT development board learning (HAL Library) - Experiment 2 buzzer experiment (learning notes)
Unity脚本的基础语法(7)-成员变量和实例化
The 6th Blue Bridge Cup single chip microcomputer provincial competition
微信小程序中 在xwml 中使用外部引入的 js进行判断计算
Qt插件之Qt Designer插件实现
Interface debugging tool simulates post upload file - apipost
0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed
The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup
蓝桥杯单片机省赛第七届
《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮
NLog use
Qt的网络连接方式
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
go 函数
Failed to upgrade schema, error: “file does not exist
Raspberry pie GPIO pin controls traffic light and buzzer
蓝桥杯单片机第四届省赛
The first practical project of software tester: web side (video tutorial + document + use case library)