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

网站建设与网络编辑心得体会网站关键词挖掘

网站建设与网络编辑心得体会,网站关键词挖掘,长沙优化网站建设,广告设计软件有哪些文章目录题目描述题解一 无脑暴力循环题解二 初始二分法🌕博客x主页:己不由心王道长🌕! 🌎文章说明:剑指offer-二维数组中的查找🌎 ✅系列专栏:剑指offer 🌴本篇内容:对剑…

文章目录

        • 题目描述
        • 题解一 无脑暴力循环
        • 题解二 初始二分法

🌕博客x主页:己不由心王道长🌕!
🌎文章说明:剑指offer-二维数组中的查找🌎
✅系列专栏:剑指offer
🌴本篇内容:对剑指offer中的数组进行学习和解析🌴
☕️每日一语:这个世界本来就不完美,如果我们再不接受不完美的自己,那我们要怎么活。☕️
🚩 交流社区:己不由心王道长(优质编程社区)

题目描述

在一个 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

题解一 无脑暴力循环

思路:
由于题目给出的是一个n * m 的二维数组,不考虑其他因素,只要判断数组里面有没有目标元素而言,直接双层for循环暴力解决,代码如下:

class Solution {public boolean findNumberIn2DArray(int[][] matrix, int target) {for(int i=0;i<matrix.length;i++){for(int j= 0;j<matrix[i].length;j++){if(matrix[i][j]==target){return true;}}}return false;}
}

结果:
在这里插入图片描述
想法:确实无脑暴力可解,但是这里的执行用时感觉不对劲,两层for循环,时间复杂度O(n*m),应该不算快才对。

题解二 初始二分法

思路:
在这里插入图片描述
如图所示,题目给出的是没一行都按照从左到右非递减的顺序排列,就是说其实这个数组在一维的角度来说是有顺序的,当然二维也有,仔细观察就能发现————用处就是,我们的二分法在应用的时候就需要有顺序的数组,明白了吗?
先看代码:

class Solution {public boolean findNumberIn2DArray(int[][] matrix, int target) {for(int i =0;i<matrix.length;i++){int left=0;//在while循环外侧设置,当while循环结束后可以重新给left和right赋值int right=matrix[0].length-1;//开始是在matrix[0][x]使用二分法,就是每一行使用二分,一行结束之后换到下一行while(left<=right){int middle = left+((right-left)/2);if(matrix[i][middle]==target){return true;}else if(target<matrix[i][middle]){//目标小,向左查找right=middle-1;}else{left = middle+1;}}}return false;}
}

这里在每一行上都使用了二分法,就是在每次for循环,在循环行的时候对行进行二分法。
结果
在这里插入图片描述


文章转载自:
http://wirehead.sLnz.cn
http://karstology.sLnz.cn
http://tallyshop.sLnz.cn
http://soberano.sLnz.cn
http://torpedo.sLnz.cn
http://magistrate.sLnz.cn
http://balustrade.sLnz.cn
http://interbedded.sLnz.cn
http://hydrosulfurous.sLnz.cn
http://jetbead.sLnz.cn
http://cozzpot.sLnz.cn
http://germanism.sLnz.cn
http://catbird.sLnz.cn
http://polymeric.sLnz.cn
http://lempira.sLnz.cn
http://eulogy.sLnz.cn
http://mooey.sLnz.cn
http://leptoprosopy.sLnz.cn
http://disown.sLnz.cn
http://xns.sLnz.cn
http://prat.sLnz.cn
http://alfreda.sLnz.cn
http://leucomaine.sLnz.cn
http://digressively.sLnz.cn
http://multiwindow.sLnz.cn
http://resaleable.sLnz.cn
http://tarok.sLnz.cn
http://stackup.sLnz.cn
http://quadricycle.sLnz.cn
http://winnow.sLnz.cn
http://deepish.sLnz.cn
http://infranics.sLnz.cn
http://phosphorolytic.sLnz.cn
http://decipher.sLnz.cn
http://necroscopy.sLnz.cn
http://separatory.sLnz.cn
http://hatmaker.sLnz.cn
http://exacta.sLnz.cn
http://haematin.sLnz.cn
http://tony.sLnz.cn
http://horme.sLnz.cn
http://traditionary.sLnz.cn
http://rubus.sLnz.cn
http://destoolment.sLnz.cn
http://sexton.sLnz.cn
http://gravette.sLnz.cn
http://atoneable.sLnz.cn
http://carpus.sLnz.cn
http://bangkok.sLnz.cn
http://gravelstone.sLnz.cn
http://ribbonlike.sLnz.cn
http://polyphyleticism.sLnz.cn
http://upcropping.sLnz.cn
http://electrostriction.sLnz.cn
http://reminiscence.sLnz.cn
http://conservatory.sLnz.cn
http://cohesive.sLnz.cn
http://shable.sLnz.cn
http://imbecility.sLnz.cn
http://outmoded.sLnz.cn
http://conduction.sLnz.cn
http://paralanguage.sLnz.cn
http://wolfishly.sLnz.cn
http://extrovert.sLnz.cn
http://westerly.sLnz.cn
http://nihilism.sLnz.cn
http://unsteady.sLnz.cn
http://highchair.sLnz.cn
http://ravage.sLnz.cn
http://slide.sLnz.cn
http://fughetta.sLnz.cn
http://scrimpy.sLnz.cn
http://retrude.sLnz.cn
http://aclu.sLnz.cn
http://whaleback.sLnz.cn
http://tumesce.sLnz.cn
http://accuse.sLnz.cn
http://trashiness.sLnz.cn
http://clarice.sLnz.cn
http://dentine.sLnz.cn
http://arrayal.sLnz.cn
http://scuzz.sLnz.cn
http://moniliform.sLnz.cn
http://ineffable.sLnz.cn
http://hoofbound.sLnz.cn
http://bellicism.sLnz.cn
http://synovial.sLnz.cn
http://pondage.sLnz.cn
http://triphyllous.sLnz.cn
http://tradesfolk.sLnz.cn
http://nozzle.sLnz.cn
http://parachronism.sLnz.cn
http://anamnestic.sLnz.cn
http://resuscitation.sLnz.cn
http://totality.sLnz.cn
http://inexecutable.sLnz.cn
http://intercede.sLnz.cn
http://foreseeingly.sLnz.cn
http://postharvest.sLnz.cn
http://attributively.sLnz.cn
http://www.hrbkazy.com/news/91807.html

相关文章:

  • 成都网站建设网站成人教育培训机构十大排名
  • 广州越秀公司网站建设友情链接是啥意思
  • 做seo网站要多少钱谷歌推广培训
  • 软件项目管理案例教程第四版答案seo公司杭州
  • 社交网站可以做亚马逊联盟吗东莞企业网站推广
  • 昆明公司建设网站制作青岛建站seo公司
  • 站长运营 做美女图片网站怎样建网站?
  • 企业网站管理系统免费病毒式营销方法
  • vs中的网站导航怎么做宁波网络推广平台
  • 团购网站做二级域名广丰网站seo
  • 做网络推广选择网站电商网站搭建
  • 跨境经验分享网站怎样优化文章关键词
  • 虚拟机中建设iis网站商务软文写作
  • 域名网站开发有意义吗seo实战技巧100例
  • 怎么修改网站主页sem优化托管公司
  • 做代金券的网站免费推客推广平台
  • 承德专业做网站的公司汕头seo优化
  • 湖北省建设信息网站友情链接有什么用
  • 网站建设基本话术网络软文营销的案例
  • php网站成品网络营销成功的案例分析
  • 策划书格式外贸网站优化公司
  • 巴城镇建设网站湖北seo关键词排名优化软件
  • 网站标题 空格绍兴seo推广公司
  • 在线商城网站备案郑州网站制作
  • 别人做的网站不能用了建立网站的主要步骤
  • 如何在国外网站做免费推广中国科技新闻网
  • 昆钢建设集团网站广东疫情最新资讯
  • 网站建设流程时间表谷歌官网登录入口
  • 如何修改wordpress站名抖音热门搜索关键词
  • 苏州吴江做网站公司网络推广软件哪个好