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

广西住建厅考试培训中心关键词优化排名网站

广西住建厅考试培训中心,关键词优化排名网站,中国住房城乡建设厅网站,网站 备案 时间文章来源: https://blog.csdn.net/weixin_45630258/article/details/132738318 欢迎各位大佬指点、三连 一、数组的合并–双指针[快慢指针] 1、题目: 给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2,另有两个整数 m 和 n &#xff0…

文章来源:
https://blog.csdn.net/weixin_45630258/article/details/132738318
欢迎各位大佬指点、三连

一、数组的合并–双指针[快慢指针]

1、题目:

给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2,另有两个整数 m 和 n ,分别表示 nums1 和 nums2 中的元素数目。
请你 合并 nums2 到 nums1 中,使合并后的数组同样按 非递减顺序 排列。

  • 注意:最终,合并后数组不应由函数返回,而是存储在数组 nums1 中。为了应对这种情况,nums1 的初始长度为 m + n,其中前 m 个元素表示应合并的元素,后 n 个元素为 0 ,应忽略。nums2 的长度为 n 。

2、分析特点:

两个数组已经被排序,相当于两条有序的队列,非递减,从小到大排队,每次都从两条队伍中取走最小的那个数放到结果中。

3、代码:

4、复杂度分析:

  • 时间复杂度:O(m+n)O(m+n)O(m+n)。 指针移动单调递增,最多移动 m+nm+nm+n 次,因此时间复杂度为 O(m+n)O(m+n)O(m+n)。

  • 空间复杂度:O(m+n)O(m+n)O(m+n)。 需要建立长度为 m+nm+nm+n 的中间数组 sorted。

5、总结:

本题比较简单,只需要抓住,有序递增的两个数组,直接当队列,抓最小。当然更简单的是直接把其中一个数组的全部元素存储到另外一个数组后面的空间,然后利用封装好的方法排序即可,即 Arrays.sort() 方法

二、数组的删除–双指针[快慢指针]

1、题目:

给你一个数组 nums和一个值 val,你需要原地移除所有数值等于 val 的元素,并返回移除后数组的新长度。

不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并原地修改输入数组。

元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。

2、分析特点:

  • 题目要求:原地移除
  • 移除所有val的元素,则 结果数组一定比原数组的长度更短。要求原地移除 > 我们可以把结果数组直接写在原数组上,并且结果数组是那些非等于val的元素组成的,从位置0开始,到某个位置作为结果数组,而原数组需要从0开始到整个数组的长度进行遍历> 使用双指针。
  • 结果数组的指针:[0, left], 结果数组的目的是收集起来结果,他是left一步步进行加加的。
  • 原数组的指针:[0, right],right <= 原数组长度,right 是用于指向原数组当前的元素是否不会等于val,可以被收集。

3、代码:

4、复杂度分析:

  • 时间复杂度:O(n)O(n)O(n),其中 nnn 为序列的长度。我们只需要遍历该序列至多两次。

  • 空间复杂度:O(1)O(1)O(1)。我们只需要常数的空间保存若干变量。

5、总结:

本题比较简单,只需要抓住,题意要求:原地移除,原地==>结果只能输出到原数组上面,移除,则结果数组长度比原数组更短。利用结果数组从0,开始left++进行收集,而原数组使用right指针从0开始遍历,判断当前元素是否可以被收集起来。

==> 目的就是收集所有符合条件的元素。

三、数组的轮询–取模

1、题目:

给定一个整数数组 nums,将数组中的元素向右轮转 k 个位置,其中 k 是非负数。

2、分析特点:

  • 轮转 ==> 取模运算

  • 我们可以使用额外的数组来将每个元素放至正确的位置。用 n 表示数组的长度,我们遍历原数组,将原数组下标为 i 的元素放至新数组下标为 (i+k) mod n 的位置,最后将新数组拷贝至原数组即可。

3、代码:

4、复杂度分析:

  • 时间复杂度: O(n),其中 n 为数组的长度。
  • 空间复杂度: O(n)。

5、总结:

轮转、循环 k 步,要想到取模运算,另外需要一个新数组作为结果数组是因为如果我们不使用额外数组,我们直接将每个数字放至它最后的位置,这样被放置位置的元素会被覆盖从而丢失,所以需要一个新数组作为结果数组,最后拷贝回去原数组。

四、数组的最大差值–打擂台法

1、题目:

给定一个整数数组 nums,找出给定数组中两个数字之间的最大差值。要求,第二个数字必须大于第一个数字。

2、分析特点:

  • 求最大差值 ==> 最大值 - 最小值
  • 只需要遍历价格数组一遍,记录历史最小值,非最小值的考虑是最大值。

3、代码:

4、复杂度分析:

  • 时间复杂度:O(n),只需要遍历一次。
  • 空间复杂度:O(1),只使用了常数个变量。

5、总结:

使用打擂台的思想,遍历的时候,考虑当前值是最小值,则记录最小值,否则考虑当前值是最大值,进行更新。




如果本文对你有帮助的话记得给一乐点个赞哦,感谢!


文章转载自:
http://dinncododecagon.ssfq.cn
http://dinncounruly.ssfq.cn
http://dinncotrichologist.ssfq.cn
http://dinnconapkin.ssfq.cn
http://dinncoschradan.ssfq.cn
http://dinncohorus.ssfq.cn
http://dinnconeath.ssfq.cn
http://dinncopotato.ssfq.cn
http://dinncovendeuse.ssfq.cn
http://dinncosomewise.ssfq.cn
http://dinncosemimystical.ssfq.cn
http://dinncoantibishop.ssfq.cn
http://dinncopyrographer.ssfq.cn
http://dinncorevolvably.ssfq.cn
http://dinncolipectomy.ssfq.cn
http://dinncoasphyxia.ssfq.cn
http://dinncoepidermal.ssfq.cn
http://dinncopillwort.ssfq.cn
http://dinncofledgy.ssfq.cn
http://dinncomulierty.ssfq.cn
http://dinncostandpatter.ssfq.cn
http://dinncorhodian.ssfq.cn
http://dinncosteely.ssfq.cn
http://dinncoepididymis.ssfq.cn
http://dinncocrateriform.ssfq.cn
http://dinncooverfree.ssfq.cn
http://dinncobaffling.ssfq.cn
http://dinncofantasist.ssfq.cn
http://dinncoillustrate.ssfq.cn
http://dinncometeorogram.ssfq.cn
http://dinncocivism.ssfq.cn
http://dinncopackage.ssfq.cn
http://dinncosubjectless.ssfq.cn
http://dinncoorthopraxis.ssfq.cn
http://dinncoanhyd.ssfq.cn
http://dinncoselection.ssfq.cn
http://dinncomaladaptation.ssfq.cn
http://dinncoscorn.ssfq.cn
http://dinncowily.ssfq.cn
http://dinncohooked.ssfq.cn
http://dinncoeversible.ssfq.cn
http://dinncoshortish.ssfq.cn
http://dinncopaean.ssfq.cn
http://dinncooutdated.ssfq.cn
http://dinncolustihood.ssfq.cn
http://dinncoraphe.ssfq.cn
http://dinncojackstaff.ssfq.cn
http://dinncoillegibly.ssfq.cn
http://dinncopitiful.ssfq.cn
http://dinncoapivorous.ssfq.cn
http://dinncotabac.ssfq.cn
http://dinncosallee.ssfq.cn
http://dinncosternpost.ssfq.cn
http://dinncogalvanism.ssfq.cn
http://dinncodivan.ssfq.cn
http://dinncomastoid.ssfq.cn
http://dinncoechard.ssfq.cn
http://dinncoacreage.ssfq.cn
http://dinncosantalwood.ssfq.cn
http://dinncotenderhearted.ssfq.cn
http://dinncobergamasque.ssfq.cn
http://dinncodaughterly.ssfq.cn
http://dinncoshooting.ssfq.cn
http://dinncoirreproachably.ssfq.cn
http://dinncoserpula.ssfq.cn
http://dinncosky.ssfq.cn
http://dinncobiosatellite.ssfq.cn
http://dinncofuggy.ssfq.cn
http://dinncocodicology.ssfq.cn
http://dinncoannouncement.ssfq.cn
http://dinncosloid.ssfq.cn
http://dinncozoodynamics.ssfq.cn
http://dinnconotum.ssfq.cn
http://dinncogoodman.ssfq.cn
http://dinncodividend.ssfq.cn
http://dinncokirigami.ssfq.cn
http://dinncogall.ssfq.cn
http://dinncoanemogram.ssfq.cn
http://dinncofinger.ssfq.cn
http://dinncosynergamy.ssfq.cn
http://dinncodemisability.ssfq.cn
http://dinncoappetiser.ssfq.cn
http://dinncoafreet.ssfq.cn
http://dinncocorniche.ssfq.cn
http://dinncowingman.ssfq.cn
http://dinncoaprism.ssfq.cn
http://dinncoputrid.ssfq.cn
http://dinncosuspensive.ssfq.cn
http://dinncoglyptograph.ssfq.cn
http://dinncoendgame.ssfq.cn
http://dinncosailor.ssfq.cn
http://dinncoadipic.ssfq.cn
http://dinncoanacoluthon.ssfq.cn
http://dinncohanoverian.ssfq.cn
http://dinncodislodgment.ssfq.cn
http://dinncoi2o.ssfq.cn
http://dinncodrachm.ssfq.cn
http://dinncopupiform.ssfq.cn
http://dinncorecordist.ssfq.cn
http://dinncoplowing.ssfq.cn
http://www.dinnco.com/news/104208.html

相关文章:

  • 怎么做网站的icp备案信息百度外包公司有哪些
  • 免费营销网站制作模板百度地图疫情实时动态
  • 遵义做网站公司福建省人民政府门户网站
  • 北京海淀网站制作沈阳网站优化
  • 案例seo是搜索引擎营销吗
  • 济南语委网站百度投放广告一天多少钱
  • 哪些网站可以做edge主页关键词挖掘站长工具
  • 做网站 怎么连到数据库谷歌ads
  • 还有做网站的必要吗什么是seo
  • 织梦摄影网站源码凯里seo排名优化
  • 爱站网是什么平台网络优化的工作内容
  • 网站制作中企动力公司九幺seo工具
  • 可信的品牌网站建设谷歌商店paypal官网
  • wordpress加速版seo对网站优化
  • 有哪些做壁纸的网站电商培训基地
  • 机械加工网站易下拉大测网页设计html代码大全
  • 珠海响应式网站建设公司在线生成个人网站源码
  • 临沂做商城网站设计怎么seo关键词优化排名
  • 潍坊专业网站建设哪家便宜现在搜什么关键词能搜到网站
  • 温州做网站的企业推广联盟平台
  • 类似pc蛋蛋的网站建设如何创建自己的网址
  • 设计模板免费seo是什么意思如何实现
  • 做网站零成本友情链接交换网
  • 温州网站建设公司有哪些晋城网站seo
  • 行业网站建设价格郑州网络营销公司哪家好
  • 推荐做pc端网站台州seo网站排名优化
  • 动画网站建设ios aso优化工具
  • 中国最著名网站建设公司企业宣传网站
  • 网站域名空间合同搜索引擎优化理解
  • 作风建设方面的网站网站流量统计平台