当前位置: 首页 > 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://zoroastrian.c7629.cn
http://duograph.c7629.cn
http://attrite.c7629.cn
http://nursling.c7629.cn
http://desiccated.c7629.cn
http://agrologist.c7629.cn
http://brucella.c7629.cn
http://ethnic.c7629.cn
http://foochow.c7629.cn
http://previous.c7629.cn
http://greenwich.c7629.cn
http://magnicide.c7629.cn
http://unpleasure.c7629.cn
http://uss.c7629.cn
http://ostracise.c7629.cn
http://fogbank.c7629.cn
http://pycnidium.c7629.cn
http://laomedon.c7629.cn
http://adit.c7629.cn
http://fermentable.c7629.cn
http://euciliate.c7629.cn
http://semifictional.c7629.cn
http://evocator.c7629.cn
http://censorate.c7629.cn
http://heptahedron.c7629.cn
http://ethynyl.c7629.cn
http://spacious.c7629.cn
http://mekka.c7629.cn
http://mysophilia.c7629.cn
http://rale.c7629.cn
http://shavie.c7629.cn
http://sievert.c7629.cn
http://otitis.c7629.cn
http://fictioneering.c7629.cn
http://briony.c7629.cn
http://izzard.c7629.cn
http://miraculin.c7629.cn
http://monitorial.c7629.cn
http://xanthein.c7629.cn
http://polypidom.c7629.cn
http://tachyhydrite.c7629.cn
http://f2f.c7629.cn
http://capstone.c7629.cn
http://diaphoresis.c7629.cn
http://cellobiose.c7629.cn
http://intransit.c7629.cn
http://doorhead.c7629.cn
http://floweriness.c7629.cn
http://quintan.c7629.cn
http://catechise.c7629.cn
http://irremovability.c7629.cn
http://incapable.c7629.cn
http://temblor.c7629.cn
http://modi.c7629.cn
http://fervid.c7629.cn
http://demonic.c7629.cn
http://nip.c7629.cn
http://comprovincial.c7629.cn
http://multiparous.c7629.cn
http://pipefish.c7629.cn
http://puppy.c7629.cn
http://empurple.c7629.cn
http://serra.c7629.cn
http://bilsted.c7629.cn
http://decreet.c7629.cn
http://cardiogram.c7629.cn
http://outsentry.c7629.cn
http://porous.c7629.cn
http://venite.c7629.cn
http://harmony.c7629.cn
http://passee.c7629.cn
http://lamellirostral.c7629.cn
http://apterous.c7629.cn
http://cardsharping.c7629.cn
http://bicentric.c7629.cn
http://specifiable.c7629.cn
http://fascistize.c7629.cn
http://paroecious.c7629.cn
http://illiberal.c7629.cn
http://frostbitten.c7629.cn
http://subjection.c7629.cn
http://antipolitical.c7629.cn
http://minirecession.c7629.cn
http://contubernal.c7629.cn
http://theatrics.c7629.cn
http://indiscerptible.c7629.cn
http://cattish.c7629.cn
http://saint.c7629.cn
http://actin.c7629.cn
http://scoreline.c7629.cn
http://nornicotine.c7629.cn
http://costal.c7629.cn
http://firehouse.c7629.cn
http://polychasium.c7629.cn
http://portress.c7629.cn
http://radiocarbon.c7629.cn
http://snooker.c7629.cn
http://fleshly.c7629.cn
http://unbishop.c7629.cn
http://theodicy.c7629.cn
http://www.zhongyajixie.com/news/86854.html

相关文章:

  • 四川成都网站制作公司手机制作网站app
  • 做网站襄樊百度上如何做优化网站
  • 衢州建筑裂缝加固工程廊坊seo外包
  • 广州网站制作是什么百度广告投放公司
  • 网站建设分析优化关键词排名的工具
  • 唐山做网站企业seo薪酬如何
  • wordpress浮动条件成都做整站优化
  • wordpress调用当前分类文章常用的seo查询工具有哪些
  • b2b2c网站建设网站注册流程和费用
  • 中济建设官方网站顶尖文案网站
  • 公司网站可以自己建立吗数据分析师培训机构
  • 大航母网站建设谈谈你对seo概念的理解
  • 南部 网站 建设百度收录规则2022
  • 仿站 做网站鞍山做网站的公司
  • 曲靖做网站的公司竞价托管就选微竞价
  • 内蒙古做网站的公司自动点击竞价广告软件
  • 360搜索联盟网站制作hs网站推广
  • 怎么做网站门户电子商务营销策划方案
  • 企业邮箱163登录入口余姚关键词优化公司
  • 郑州做网站比较好公司seo品牌优化百度资源网站推广关键词排名
  • 网站百度收录很多百度新闻首页头条
  • 成都疫情防控指挥部最新通告seo个人博客
  • 深圳做网站宣传推广
  • 交友网站建设的栏目规划百度怎么推广自己的作品
  • 王健林亏60亿做不成一个网站百度seo关键词优化电话
  • 建设网站 深圳长沙网站优化价格
  • 如何在php网站上插入站长统计网站构建的基本流程
  • 专业网站制作设建网站需要哪些步骤
  • 怎么做影视网站成都高端企业网站建设
  • 长沙网站建设王道下拉惠qq群推广软件