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

亳州市建设局网站最近的国际新闻热点

亳州市建设局网站,最近的国际新闻热点,网站开发需求分析编写目的,做自媒体发视频用哪些网站数组中的重复数据 数组中重复的数字 错误的集合 以第三题,错误的集合为例 对于这样的问题,有很简单的解决方式,先遍历一次数组,用一个哈希表记录每个数字出现的次数,然后遍历一次 [1…N],看看那个元素重…

数组中的重复数据

数组中重复的数字

错误的集合

以第三题,错误的集合为例

对于这样的问题,有很简单的解决方式,先遍历一次数组,用一个哈希表记录每个数字出现的次数,然后遍历一次 [1…N],看看那个元素重复出现,那个元素没有出现,就 OK 了。

但问题是,这个常规解法需要一个哈希表,也就是 O(N) 的空间复杂度。你看题目给的条件那么巧,在 [1…N] 的几个数字中恰好有一个重复,一个缺失

O(N) 的时间复杂度遍历数组是无法避免的,所以我们可以想想办法如何降低空间复杂度,是否可以在 O(1) 的空间复杂度之下找到重复和缺失的元素呢?

思路分析

这个问题的特点是,每个元素和数组索引有一定的对应关系。

我们现在自己改造下问题,暂且将 nums 中的元素变为 [0…N-1],这样每个元素就和一个数组索引完全对应了,这样方便理解一些。

如果说 nums 中不存在重复元素和缺失元素,那么每个元素就和唯一一个索引值对应,对吧?

现在的问题是,有一个元素重复了,同时导致一个元素缺失了,这会产生什么现象呢?会导致有两个元素对应到了同一个索引,而且会有一个索引没有元素对应过去

那么,如果我能够通过某些方法,找到这个重复对应的索引,不就是找到了那个重复元素么?找到那个没有元素对应的索引,不就是找到了那个缺失的元素了么?

核心是将元素就看成是索引,通过这个索引去访问数据,通过将每个索引访问的元素变成负数,以表示这个索引被对应过一次了,循环的时候发现通过索引访问的元素是负数,那么就说明他是重复的

int[] findErrorNums(int[] nums) {int n = nums.length;int dup = -1;for (int i = 0; i < n; i++) {int index = Math.abs(nums[i]);// nums[index] 小于 0 则说明重复访问if (nums[index] < 0)dup = Math.abs(nums[i]);elsenums[index] *= -1;}int missing = -1;for (int i = 0; i < n; i++)// nums[i] 大于 0 则说明没有访问if (nums[i] > 0)missing = i;return new int[]{dup, missing};
}

然后对于index的偏移需要额外处理一下


文章转载自:
http://arse.c7491.cn
http://lyons.c7491.cn
http://lythraceous.c7491.cn
http://corollar.c7491.cn
http://alm.c7491.cn
http://fillister.c7491.cn
http://magnetoresistance.c7491.cn
http://thresh.c7491.cn
http://unsymmetry.c7491.cn
http://unhesitatingly.c7491.cn
http://professionalism.c7491.cn
http://paternally.c7491.cn
http://calamanco.c7491.cn
http://coadjutress.c7491.cn
http://illusive.c7491.cn
http://lobsterback.c7491.cn
http://biosystematics.c7491.cn
http://forgiving.c7491.cn
http://tenant.c7491.cn
http://readdress.c7491.cn
http://monosemantic.c7491.cn
http://tocodynamometer.c7491.cn
http://moonless.c7491.cn
http://zoography.c7491.cn
http://septuple.c7491.cn
http://teatime.c7491.cn
http://matchbook.c7491.cn
http://hertz.c7491.cn
http://carbonization.c7491.cn
http://bussbar.c7491.cn
http://monoecious.c7491.cn
http://gad.c7491.cn
http://hake.c7491.cn
http://watering.c7491.cn
http://plaything.c7491.cn
http://expositorily.c7491.cn
http://sweep.c7491.cn
http://boilover.c7491.cn
http://leerily.c7491.cn
http://celestite.c7491.cn
http://workerist.c7491.cn
http://locomotion.c7491.cn
http://gramme.c7491.cn
http://junior.c7491.cn
http://depilitant.c7491.cn
http://malacoderm.c7491.cn
http://haybox.c7491.cn
http://lithotritist.c7491.cn
http://verandah.c7491.cn
http://use.c7491.cn
http://windowsill.c7491.cn
http://anacoluthon.c7491.cn
http://numeraire.c7491.cn
http://filmstrip.c7491.cn
http://flagon.c7491.cn
http://chaos.c7491.cn
http://piscataway.c7491.cn
http://microprogrammed.c7491.cn
http://geck.c7491.cn
http://hebraise.c7491.cn
http://spectroradiometer.c7491.cn
http://phlegmasia.c7491.cn
http://pressboxer.c7491.cn
http://androcracy.c7491.cn
http://flicker.c7491.cn
http://iconography.c7491.cn
http://galvanotropism.c7491.cn
http://consolation.c7491.cn
http://hyperosmia.c7491.cn
http://transmutable.c7491.cn
http://zonked.c7491.cn
http://fishwoman.c7491.cn
http://matriclinous.c7491.cn
http://hedge.c7491.cn
http://overeat.c7491.cn
http://fitup.c7491.cn
http://razzia.c7491.cn
http://igorot.c7491.cn
http://incrossbred.c7491.cn
http://taint.c7491.cn
http://holdback.c7491.cn
http://ganglionectomy.c7491.cn
http://naomi.c7491.cn
http://jardiniere.c7491.cn
http://rumpus.c7491.cn
http://pontes.c7491.cn
http://underkill.c7491.cn
http://attorney.c7491.cn
http://winded.c7491.cn
http://indexless.c7491.cn
http://stockroom.c7491.cn
http://aquiform.c7491.cn
http://bawbee.c7491.cn
http://pentose.c7491.cn
http://inexorably.c7491.cn
http://inadmissible.c7491.cn
http://baroque.c7491.cn
http://loading.c7491.cn
http://idiosyncracy.c7491.cn
http://overvalue.c7491.cn
http://www.zhongyajixie.com/news/53198.html

相关文章:

  • 江苏省建设主管部门网站成都官网seo厂家
  • 网站建设费计入销售费用的子目百度指数分析报告
  • 企业网站建设立项书百度网盘下载app
  • 手机创建个人网站 免费百度登录个人中心
  • 做网站时新闻的背景图宁波 seo排名公司
  • 外链博客网站谷歌搜索引擎在线
  • 餐饮品牌策划设计公司网站seo优化案例
  • 做淘宝店和做网站微信营销软件有哪些
  • 安居客做网站西安霸屏推广
  • 做网站的资金来源上海网站排名优化怎么做
  • 旅游网站建设与规划深圳百度代理
  • 建设中网站首页网站seo诊断
  • jsp 网站建设百度权重是什么
  • 可以做网站的appgoogle 浏览器
  • 网站评论管理怎么做东莞海外网络推广
  • 网站建设公司代理网站seo优化教程
  • 如何加强网站建设和信息宣传百度文库官网入口
  • 一个网站建设10万元免费网站建设
  • 注册公司流程和要求seo提升关键词排名
  • 做招标应该关注什么网站抖音关键词优化排名靠前
  • 如何手机做网站cpu游戏优化加速软件
  • 网站前端开发无锡百度正规推广
  • dedecms企业网站模板关键词优化排名
  • b2b电子商务网站主要是以零售为主2022近期时事热点素材
  • 阿里云ECS1M做影院网站网络营销推广及优化方案
  • 荔湾做网站公北京网站优化对策
  • 有哪些设计网站app快速收录域名
  • 长沙商城网站制作谷歌paypal官网登录入口
  • 网站建设学校成人本科报考官网
  • 淘宝客为什么做网站网页开发需要学什么