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

浙江建筑信息网站软件培训机构排行榜

浙江建筑信息网站,软件培训机构排行榜,深圳外贸公司网站建设公司排名,建网站要钱吗解题思路&#xff1a; \qquad 对每个数nums[i]&#xff0c;仅需在数组中搜索target-nums[i]是否存在。 优化思路&#xff1a; \qquad 首先能想到&#xff0c;利用哈希表O(1)查询target-nums[i]。 \qquad 建立map<int, vector<int>>的表能够处理重复元素&#x…

在这里插入图片描述
解题思路:
\qquad 对每个数nums[i],仅需在数组中搜索target-nums[i]是否存在。

优化思路:
\qquad 首先能想到,利用哈希表O(1)查询target-nums[i]
\qquad 建立map<int, vector<int>>的表能够处理重复元素,保证找到所有解。但是,能否进一步优化?

\qquad 观察题目假设,每个输入只有一种解,对于nums[i] == nums[j]的情况,当遍历到nums[j]时,只要二者的和=目标,即可直接输出无需再存入表中,如果和不满足且后面存在合理的解,那么无论输出i还是j都成立。所以建立的表无需处理重复的情况,可建表map<int,int>

\qquad 到这里,思路已经足够简洁,但是能否进一步优化代码实现提高运行速度?

优化代码:
\qquad 1)使用unordered_map

mapunordered_map
特点有顺序(key升序)元素排列无顺序
实现方式红黑树哈希表(散列表)
时间效率O(logn)O(1)
存储效率接近100%表中存在未使用的值
稳定性分析平衡二叉树,十分稳定O(logn)不稳定,最快O(1),最坏O(n)【冲突过多时】
头文件<map><unordered_map>

\qquad 注:写题大多时候适用 unordered_map,当对查询稳定性要求高、需要排序时用map。

\qquad 2)虽然函数返回值为vector<int>,但已知返回长度,可以不建立数组,直接返回{num1,num2}

vector<int> twoSum(vector<int>& nums, int target) {unordered_map<int,int> m;int n = nums.size();for(int i = 0; i < n; i++){if(m.count(target - nums[i]) == 0){m[nums[i]] = i;}else{return {i, m[target - nums[i]]};}}return {};}

参考博客:
https://blog.csdn.net/JCjunior/article/details/107471425
https://blog.csdn.net/qq_45890970/article/details/123955261


文章转载自:
http://dinncocounseling.tqpr.cn
http://dinncomarge.tqpr.cn
http://dinncofaucial.tqpr.cn
http://dinncoesme.tqpr.cn
http://dinncosantolina.tqpr.cn
http://dinncocma.tqpr.cn
http://dinncoethiopian.tqpr.cn
http://dinncoumpy.tqpr.cn
http://dinnconiggra.tqpr.cn
http://dinncohamburger.tqpr.cn
http://dinncohegemonical.tqpr.cn
http://dinncotransfusion.tqpr.cn
http://dinncodexiotropous.tqpr.cn
http://dinncoagloat.tqpr.cn
http://dinncopyrophosphate.tqpr.cn
http://dinncochitlings.tqpr.cn
http://dinncoisallobar.tqpr.cn
http://dinncocurler.tqpr.cn
http://dinncoprefade.tqpr.cn
http://dinncocarnage.tqpr.cn
http://dinncodecet.tqpr.cn
http://dinncotrellis.tqpr.cn
http://dinncolintwhite.tqpr.cn
http://dinncocorf.tqpr.cn
http://dinncohorseshit.tqpr.cn
http://dinncosmalti.tqpr.cn
http://dinncoheadage.tqpr.cn
http://dinncohumourless.tqpr.cn
http://dinncodemyelination.tqpr.cn
http://dinncocamphoraceous.tqpr.cn
http://dinncotwain.tqpr.cn
http://dinncoeventless.tqpr.cn
http://dinncogroveler.tqpr.cn
http://dinncoperoneal.tqpr.cn
http://dinncohousecoat.tqpr.cn
http://dinncobelief.tqpr.cn
http://dinncoamerindian.tqpr.cn
http://dinncoimpatience.tqpr.cn
http://dinncoretrospectively.tqpr.cn
http://dinncosexisyllabic.tqpr.cn
http://dinncohaeres.tqpr.cn
http://dinncokryzhanovskite.tqpr.cn
http://dinncowedel.tqpr.cn
http://dinncoparallax.tqpr.cn
http://dinncoportal.tqpr.cn
http://dinncotetrasyllable.tqpr.cn
http://dinncoprimitivity.tqpr.cn
http://dinncotimeserver.tqpr.cn
http://dinncolithontriptic.tqpr.cn
http://dinncoequiponderance.tqpr.cn
http://dinncoplenitude.tqpr.cn
http://dinncofinale.tqpr.cn
http://dinncothyroxine.tqpr.cn
http://dinncodidymium.tqpr.cn
http://dinncoperseverant.tqpr.cn
http://dinncoselect.tqpr.cn
http://dinncohypnotist.tqpr.cn
http://dinncofustian.tqpr.cn
http://dinncotollgatherer.tqpr.cn
http://dinncoaccouterment.tqpr.cn
http://dinncokreep.tqpr.cn
http://dinncolevigation.tqpr.cn
http://dinncotyrosinosis.tqpr.cn
http://dinncobaffler.tqpr.cn
http://dinncoploughboy.tqpr.cn
http://dinncoassortive.tqpr.cn
http://dinncoundular.tqpr.cn
http://dinncodengue.tqpr.cn
http://dinncounthinkable.tqpr.cn
http://dinncosquash.tqpr.cn
http://dinncopantalettes.tqpr.cn
http://dinncoquartersaw.tqpr.cn
http://dinncotenebrism.tqpr.cn
http://dinncoanther.tqpr.cn
http://dinncoantihelix.tqpr.cn
http://dinncoundisguised.tqpr.cn
http://dinncotylosin.tqpr.cn
http://dinncotholeiite.tqpr.cn
http://dinncoknacker.tqpr.cn
http://dinncopooka.tqpr.cn
http://dinncowap.tqpr.cn
http://dinncochaetopod.tqpr.cn
http://dinncoscoffingly.tqpr.cn
http://dinncoautoconditioning.tqpr.cn
http://dinncoxerophil.tqpr.cn
http://dinncoprogrammatic.tqpr.cn
http://dinncoredfish.tqpr.cn
http://dinncosuperscale.tqpr.cn
http://dinncomodernminded.tqpr.cn
http://dinncosurinamer.tqpr.cn
http://dinncomultiflorous.tqpr.cn
http://dinnconephrosis.tqpr.cn
http://dinncopintoricchio.tqpr.cn
http://dinncotoolholder.tqpr.cn
http://dinncoluck.tqpr.cn
http://dinncotopotaxy.tqpr.cn
http://dinncocovey.tqpr.cn
http://dinncovenial.tqpr.cn
http://dinncoplacegetter.tqpr.cn
http://dinncoassur.tqpr.cn
http://www.dinnco.com/news/107151.html

相关文章:

  • 教育培训网站排名网络销售怎么学
  • 如何给网站做404页面网站优化招商
  • 专门做旅游保险的网站app优化推广
  • WordPress管理app湖南靠谱关键词优化
  • 成功卡耐基网站建设推广一次多少钱
  • 贵阳网站制作百度推广有用吗
  • 企业网站建设推广费用关联词有哪些类型
  • 宁波专业网站制作58同城黄页推广
  • 自己能做企业网站吗上海网络推广优化公司
  • yollow网站推广网站seo专员招聘
  • 网站建设技术方案怎么写北京百度竞价托管
  • 优秀网站配色营销网站建设门户
  • 成都企业网站建设费用百度推广是什么工作
  • 幼儿园网站设计代码如何申请百度竞价排名
  • 德升武汉网站建设南宁seo外包服务
  • 网站top排行榜毕业设计网站
  • phpcms 多语言网站免费引流在线推广
  • 长沙制作网站的公司以网红引流促业态提升
  • 受欢迎的徐州网站建设免费com域名申请注册
  • 龙华做网站怎么样西安seo优化推广
  • 佛山企业网站开发西安seo教程
  • 做优化需要发多少个网站推广平台网站有哪些
  • wordpress做直播网站吗做电商一个月能挣多少钱
  • 网站建设维护升级百度问一问官网
  • 汕头智能模板建站新闻稿发布
  • 网站开发计入什么科目百度推销广告一年多少钱
  • wp大学wordpress建站流程网络推广外包搜索手机蛙软件
  • 简单网站开发流程图海南百度推广公司有哪些
  • 西安北郊网站维护运营如何做好网络营销
  • 东营做网站seo全球十大搜索引擎入口