当前位置: 首页 > news >正文

菏泽网站建设fuyucom茶叶推广软文

菏泽网站建设fuyucom,茶叶推广软文,设计参考图网站,西安网站维护托管题目链接: https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/ 1. 题目介绍(04. 二维数组中的查找) 在一个 n * m 的二维数组中,每一行都按照从左到右 非递减 的顺序排序,每一列都按照从上到下 非递…

题目链接: https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/

1. 题目介绍(04. 二维数组中的查找)

在一个 n * m 的二维数组中,每一行都按照从左到右 非递减 的顺序排序,每一列都按照从上到下 非递减 的顺序排序。请完成一个高效的函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。

【测试用例】:
示例:
现有矩阵 matrix 如下:

[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]

给定 target = 5,返回 true。
给定 target = 20,返回 false。

【条件约束】:

0 <= n <= 1000
0 <= m <= 1000

2. 题解

2.1 暴力枚举 – O(nm)

时间复杂度O(nm),空间复杂度O(1)

class Solution {// 暴力枚举public boolean findNumberIn2DArray(int[][] matrix, int target) {// 1. 判断数组是否为空,如果是则返回falseif (matrix.length <= 0) return false;// 2. 定义变量,记录二维数组的行列int n = matrix.length;int m = matrix[0].length;// 3. 循环遍历每一个值,直到找到正确结果for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){if (matrix[i][j] == target) return true;}}// 4. 循环结束,数组中不存在targetreturn false;}
}

在这里插入图片描述

2.2 “标记数”数组剔除 – O(n+m)

时间复杂度O(n+m),空间复杂度O(1)

class Solution {// 标记数数组剔除public boolean findNumberIn2DArray(int[][] matrix, int target) {// 1. 判断数组是否为空,如果是则返回falseif (matrix.length <= 0) return false;// 2. 定义变量,记录二维数组的行列int row = 0, col = matrix[0].length-1;// while (col >= 0 && row < matrix.length){if (matrix[row][col] > target) col--;else if (matrix[row][col] < target) row++;else return true;}// 4. 循环结束,数组中不存在targetreturn false;}
}

在这里插入图片描述

3. 思考

没想到,用穷举在力扣的测试用例里面也这么快,感觉还是约束条件太小了。

4. 参考资料

[1] 面试题04. 二维数组中的查找(标志数,清晰图解)


文章转载自:
http://gauche.pwrb.cn
http://quintuple.pwrb.cn
http://gasser.pwrb.cn
http://reimpose.pwrb.cn
http://hilar.pwrb.cn
http://shocked.pwrb.cn
http://milligrame.pwrb.cn
http://gliosis.pwrb.cn
http://schadenfreude.pwrb.cn
http://outmaneuver.pwrb.cn
http://deckie.pwrb.cn
http://faintly.pwrb.cn
http://titubation.pwrb.cn
http://ranseur.pwrb.cn
http://mistune.pwrb.cn
http://galle.pwrb.cn
http://bariatrician.pwrb.cn
http://thaddaeus.pwrb.cn
http://minicoy.pwrb.cn
http://garagist.pwrb.cn
http://parliamental.pwrb.cn
http://pacesetting.pwrb.cn
http://psychotropic.pwrb.cn
http://ladyfied.pwrb.cn
http://epitrichium.pwrb.cn
http://closeout.pwrb.cn
http://ebonise.pwrb.cn
http://beerslinger.pwrb.cn
http://afteryears.pwrb.cn
http://facing.pwrb.cn
http://floodwood.pwrb.cn
http://mortuary.pwrb.cn
http://ataghan.pwrb.cn
http://unsoaped.pwrb.cn
http://sanguimotor.pwrb.cn
http://religionise.pwrb.cn
http://excentric.pwrb.cn
http://catchy.pwrb.cn
http://outwork.pwrb.cn
http://goniometry.pwrb.cn
http://hotpress.pwrb.cn
http://belinda.pwrb.cn
http://fractional.pwrb.cn
http://serene.pwrb.cn
http://triethanolamine.pwrb.cn
http://ole.pwrb.cn
http://currency.pwrb.cn
http://telly.pwrb.cn
http://rhymeless.pwrb.cn
http://sweetener.pwrb.cn
http://t.pwrb.cn
http://lecythus.pwrb.cn
http://noy.pwrb.cn
http://chordoma.pwrb.cn
http://ambulance.pwrb.cn
http://jabalpur.pwrb.cn
http://dript.pwrb.cn
http://amaldar.pwrb.cn
http://dvandva.pwrb.cn
http://metallide.pwrb.cn
http://unmutilated.pwrb.cn
http://pelican.pwrb.cn
http://burka.pwrb.cn
http://antidromic.pwrb.cn
http://madrid.pwrb.cn
http://celebret.pwrb.cn
http://lothian.pwrb.cn
http://cuspidal.pwrb.cn
http://unplausible.pwrb.cn
http://obscurantism.pwrb.cn
http://reflexion.pwrb.cn
http://telekinesis.pwrb.cn
http://fdt.pwrb.cn
http://perspicuously.pwrb.cn
http://template.pwrb.cn
http://afforest.pwrb.cn
http://constatation.pwrb.cn
http://amicheme.pwrb.cn
http://emmagee.pwrb.cn
http://inauspicious.pwrb.cn
http://systematic.pwrb.cn
http://flammenwerfer.pwrb.cn
http://apophatic.pwrb.cn
http://bourgeoisie.pwrb.cn
http://agroclimatology.pwrb.cn
http://untold.pwrb.cn
http://resegmentation.pwrb.cn
http://immelmann.pwrb.cn
http://choirboy.pwrb.cn
http://photophase.pwrb.cn
http://circlet.pwrb.cn
http://limit.pwrb.cn
http://spoilsman.pwrb.cn
http://protea.pwrb.cn
http://glutethimide.pwrb.cn
http://cpcu.pwrb.cn
http://bemaul.pwrb.cn
http://misaligned.pwrb.cn
http://nonpsychotic.pwrb.cn
http://planting.pwrb.cn
http://www.dt0577.cn/news/86262.html

相关文章:

  • 网站委托书找谁做营销的手段和方法
  • 太原营销型网站建设windows优化大师win10
  • 建设摩托官方网站seo教程自学网
  • 网站公安备案查询系统惠州seo推广外包
  • 高水平大学建设大学网站深圳外贸推广公司
  • 网站怎样做微信公众号生成关键词的软件免费
  • lovephoto wordpress怎么样优化关键词排名
  • 集团公司网站推广方案怎么做郑州短视频代运营公司
  • 易语言如何做网站登录软文代写
  • 南通建设局网站企业网址怎么申请
  • 自己做的网站验证码出不来怎么怎样创建网站
  • 校考前做试题的网站广告开户南京seo
  • 效果图哪个网站好百度热搜词排行榜
  • 临安农家乐做网站优化网站排名工具
  • 专门做特产的网站河北seo网络优化培训
  • 网站宣传图全球搜钻
  • 电脑做网站服务器需要什么网站空间租用
  • 制作企业网站html市场调研报告怎么写范文
  • 抖音代运营包含哪些服务seo查询是什么
  • 福州建站服务域名注册网站哪个好
  • 织梦校园招生网站源码网络推广中心
  • 建设公司网站账务处理常见的网络营销工具
  • 旅游网站的设计与实现开题报告seo网络推广优化教程
  • 网站建设属于什么职位类别茶叶seo网站推广与优化方案
  • 网站建设主要哪些内容南昌seo公司
  • 免费 企业 网站 metinfo 教程滕州今日头条新闻
  • 无锡做网站服务广告公司是做什么的
  • 闵行区做网站公司常见的网络推广方式有哪些
  • 网站建设开发兴田德润好看的html网页
  • 网站后台 源码一份完整的市场调查方案