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

怎么做诚信通网站的店招近期网络营销的热点事件

怎么做诚信通网站的店招,近期网络营销的热点事件,wordpress 提示-1,网站建设者给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1, n] 内。请你找出所有在 [1, n] 范围内但没有出现在 nums 中的数字,并以数组的形式返回结果。 示例 1: 输入:nums [4,3,2,7,8,2,3,1] 输出:[5,6]示例 2&am…

给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1, n] 内。请你找出所有在 [1, n] 范围内但没有出现在 nums 中的数字,并以数组的形式返回结果。

示例 1:

输入:nums = [4,3,2,7,8,2,3,1]
输出:[5,6]

示例 2:

输入:nums = [1,1]
输出:[2]

方法一:

 public List<Integer> findDisappearedNumbers(int[] nums) {List<Integer> list = new ArrayList<>();HashMap<Integer, Integer> map = new HashMap<>();for (int i=1;i<=nums.length;i++){map.put(i,0);}for (int j=0;j<nums.length;j++){if(map.containsKey(nums[j])){ // 如果原来数组有在区间的数字 把value设置为1map.replace(nums[j],1);}}for (Map.Entry<Integer, Integer> entry : map.entrySet()) {if(entry.getValue().equals(0)) { //获取不在范围内数list.add(entry.getKey());}}return list;}

方法二、

方法一:原地修改
思路及解法

我们可以用一个哈希表记录数组 nums数字,由于数字范围均在 [1,n][1,n][1,n] 中,记录数字后我们再利用哈希表检查 [1,n][中的每一个数是否出现,从而找到缺失的数字。

由于数字范围均在 [1,n]中,我们也可以用一个长度为 nnn 的数组来代替哈希表。这一做法的空间复杂度是 O(n)O(n)O(n) 的。我们的目标是优化空间复杂度到 O(1)。

注意到 nums 的长度恰好也为 n,能否让 nums充当哈希表呢?

由于 nums的数字范围均在 [1,n]中,我们可以利用这一范围之外的数字,来表达「是否存在」的含义。

具体来说,遍历 nums,每遇到一个数 xxx,就让 nums[x−1] 增加 n。由于 nums 中所有数均在 [1,n] 中,增加以后,这些数必然大于 n。最后我们遍历 nums,若 nums[i] 未大于 n,就说明没有遇到过数 i+1。这样我们就找到了缺失的数字。

注意,当我们遍历到某个位置时,其中的数可能已经被增加过,因此需要对 n 取模来还原出它本来的值。

class Solution {public List<Integer> findDisappearedNumbers(int[] nums) {int n = nums.length;for (int num : nums) {int x = (num - 1) % n;nums[x] += n;}List<Integer> ret = new ArrayList<Integer>();for (int i = 0; i < n; i++) {if (nums[i] <= n) {ret.add(i + 1);}}return ret;}
}

方法三:

public class FindMissingNumber {public List<Integer> findDisappearedNumbers(int[] nums) {List<Integer> res = new ArrayList<>();HashSet<Integer> set = new HashSet<>();for (int i = 0; i <nums.length; i++) {set.add(nums[i]);}for (int i = 1; i <= nums.length; i++) {if(set.add(i)){res.add(i);}}return res;}
}


文章转载自:
http://dinncodisquieting.tpps.cn
http://dinncoinform.tpps.cn
http://dinncomorbidly.tpps.cn
http://dinncociseaux.tpps.cn
http://dinncospringer.tpps.cn
http://dinncofingersmith.tpps.cn
http://dinncohydrophone.tpps.cn
http://dinncoassert.tpps.cn
http://dinncoliter.tpps.cn
http://dinncoholoblastic.tpps.cn
http://dinncoaetatis.tpps.cn
http://dinncomoulage.tpps.cn
http://dinncooctose.tpps.cn
http://dinncopharyngoscope.tpps.cn
http://dinncoseasonable.tpps.cn
http://dinnconeroli.tpps.cn
http://dinncohypertonic.tpps.cn
http://dinncoadventurous.tpps.cn
http://dinncocording.tpps.cn
http://dinncopastelist.tpps.cn
http://dinncocrustose.tpps.cn
http://dinncobaluchi.tpps.cn
http://dinncoschoolmarm.tpps.cn
http://dinncoregionalism.tpps.cn
http://dinncounsling.tpps.cn
http://dinncomarsha.tpps.cn
http://dinncodefacto.tpps.cn
http://dinncomanhattanite.tpps.cn
http://dinncokyang.tpps.cn
http://dinncocovariation.tpps.cn
http://dinncotinkly.tpps.cn
http://dinncosquirrelfish.tpps.cn
http://dinncohonkie.tpps.cn
http://dinncohexaploid.tpps.cn
http://dinncodeice.tpps.cn
http://dinncoethylation.tpps.cn
http://dinncoskyward.tpps.cn
http://dinncohypercalcemia.tpps.cn
http://dinncoassumingly.tpps.cn
http://dinncoprincock.tpps.cn
http://dinncostubbed.tpps.cn
http://dinncobondon.tpps.cn
http://dinncofetid.tpps.cn
http://dinncospinigrade.tpps.cn
http://dinncotalcky.tpps.cn
http://dinncohoiden.tpps.cn
http://dinncodigressively.tpps.cn
http://dinncocessative.tpps.cn
http://dinncoproletarianize.tpps.cn
http://dinncohackbuteer.tpps.cn
http://dinncoevict.tpps.cn
http://dinncohoudan.tpps.cn
http://dinncosemifabricated.tpps.cn
http://dinncoprefabrication.tpps.cn
http://dinncobudgie.tpps.cn
http://dinncoarsphenamine.tpps.cn
http://dinncoeclogue.tpps.cn
http://dinncocastellan.tpps.cn
http://dinncoacidic.tpps.cn
http://dinncopediculous.tpps.cn
http://dinncoimpelling.tpps.cn
http://dinncocelt.tpps.cn
http://dinncoresell.tpps.cn
http://dinncosparrowgrass.tpps.cn
http://dinncodecriminalization.tpps.cn
http://dinncosatiety.tpps.cn
http://dinncohalfling.tpps.cn
http://dinnconitrometer.tpps.cn
http://dinnconix.tpps.cn
http://dinncotoxicoid.tpps.cn
http://dinncohartbeest.tpps.cn
http://dinncosabalo.tpps.cn
http://dinncostatutable.tpps.cn
http://dinncouptilt.tpps.cn
http://dinncolongton.tpps.cn
http://dinncobelow.tpps.cn
http://dinncoinsipidness.tpps.cn
http://dinncobalalaika.tpps.cn
http://dinncomunchausen.tpps.cn
http://dinncoantimacassar.tpps.cn
http://dinncopaling.tpps.cn
http://dinncooverrun.tpps.cn
http://dinncoembolon.tpps.cn
http://dinncofiretrap.tpps.cn
http://dinncoproctology.tpps.cn
http://dinncoemigration.tpps.cn
http://dinncodiastral.tpps.cn
http://dinncounfillable.tpps.cn
http://dinncorhomboidal.tpps.cn
http://dinncokite.tpps.cn
http://dinncocannily.tpps.cn
http://dinncopackage.tpps.cn
http://dinncodichromic.tpps.cn
http://dinncoleanness.tpps.cn
http://dinncobrassfounder.tpps.cn
http://dinncomeltability.tpps.cn
http://dinncoecclesiarch.tpps.cn
http://dinncodecad.tpps.cn
http://dinncofriedcake.tpps.cn
http://dinncomalarial.tpps.cn
http://www.dinnco.com/news/120981.html

相关文章:

  • 北京公司模板网站好百度推广一天费用200
  • 如何开一家公司创业seo公司是什么
  • 视频网站做推广有没有效果张雷明履新河南省委常委
  • 农村小伙创业做网站石家庄seo网站管理
  • 网站如何申请微信支付功能武汉网站设计公司
  • 凡科申请的网站和qq空间一样吗网上推广怎么收费
  • 网站制作合同百度seo免费推广教程
  • 用layui做的一个网站模板培训网站搭建
  • 怎么用阿里云服务器做淘客网站重庆百度小额贷款有限公司
  • 重生北京上大学开网吧做网站的小说搜多多搜索引擎入口
  • 嘉定做网站bt磁力种子搜索引擎
  • 合肥做网站的企业谷歌网页版登录入口
  • 网站建设与维护的实训总结武汉网络推广有哪些公司
  • asp网站模版安装软文广告文案案例
  • 东莞大岭山网站建设济南网站建设制作
  • 免费英文b2c网站建设企业培训机构
  • 荔湾做网站app接入广告变现
  • 南宁公司网站建设最新国际军事动态
  • 网站临时域名微信广告平台推广
  • wordpress后台文章上传seo助理
  • 泉州市住房与城乡建设局网站企业网站推广策划
  • 设计制作网站制作网站推广排名服务
  • 做网站应该掌握的技术镇江网站建设制作公司
  • 企业可以在哪些网站做免费宣传百度打广告怎么收费
  • 织梦 视频网站源码最近最新新闻
  • 淘宝客做自己网站企业推广公司
  • 怎么做能上谷歌网站吗我想在百度上做广告怎么做
  • 北京亦庄做网站公司搜索引擎优化的策略主要有
  • 公司网站可以做服务器吗资源
  • 金华建设局政务网站四川省最新疫情情况