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

温州网站建设方案书推广app赚佣金接单平台

温州网站建设方案书,推广app赚佣金接单平台,wordpress 网站静态,广告设计公司总监年度总结代码随想录二刷 | 哈希表 |四数相加II 题目描述解题思路 & 代码实现 题目描述 454.四数相加II 给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n ,请你计算有多少个元组 (i, j, k, l) 能满足: 0…

代码随想录二刷 | 哈希表 |四数相加II

  • 题目描述
  • 解题思路 & 代码实现

题目描述

454.四数相加II

给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n ,请你计算有多少个元组 (i, j, k, l) 能满足:

  • 0 <= i, j, k, l < n
  • nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0

示例 1:

输入:nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]
输出:2
解释:
两个元组如下:

  1. (0, 0, 0, 1) -> nums1[0] + nums2[0] + nums3[0] + nums4[1] = 1 + (-2) + (-1) + 2 = 0
  2. (1, 1, 0, 0) -> nums1[1] + nums2[1] + nums3[0] + nums4[0] = 2 + (-1) + (-1) + 0 = 0

示例 2:

输入:nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]
输出:1

提示:

  • n == nums1.length
  • n == nums2.length
  • n == nums3.length
  • n == nums4.length
  • 1 <= n <= 200
  • -228 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 228

解题思路 & 代码实现

这道题目是四个独立的数组,只要找到A[i] + B[j] + C[k] + D[l] = 0就可以,不用考虑有重复的四个元素相加等于0的情况。

本题解题步骤:

  1. 首先定义 一个unordered_map,key放a和b两数之和,value 放a和b两数之和出现的次数。
  2. 遍历大A和大B数组,统计两个数组元素之和,和出现的次数,放到map中。
  3. 定义int变量count,用来统计 a+b+c+d = 0 出现的次数。
  4. 在遍历大C和大D数组,找到如果 0-(c+d) 在map中出现过的话,就用count把map中key对应的value也就是出现次数统计出来
  5. 最后返回统计值 count
class Solution {
public:int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {unordered_map<int, int> umap;for (int a : A) {for (int b : B) {umap[a + b]++;}}int count = 0;for (int c : C) {for (int d : D) {if (umap.find(0 - (c + d)) ! = umap.end()) {count += umap[0 - (c + d)];}}}return count;}
};

时间复杂度:O(n^2)
空间复杂度:O(n^2),最坏情况下A和B的值各不相同,相加产生的数字个数为n ^ 2


文章转载自:
http://visualist.bpcf.cn
http://embryectomy.bpcf.cn
http://mitosis.bpcf.cn
http://tropism.bpcf.cn
http://transship.bpcf.cn
http://unofficial.bpcf.cn
http://outsole.bpcf.cn
http://semiotics.bpcf.cn
http://gradational.bpcf.cn
http://pully.bpcf.cn
http://rhombohedron.bpcf.cn
http://disulfuram.bpcf.cn
http://intangibility.bpcf.cn
http://concretist.bpcf.cn
http://lattermost.bpcf.cn
http://haver.bpcf.cn
http://zetland.bpcf.cn
http://hist.bpcf.cn
http://slub.bpcf.cn
http://box.bpcf.cn
http://triboluminescence.bpcf.cn
http://initializtion.bpcf.cn
http://intransit.bpcf.cn
http://cainogenesis.bpcf.cn
http://resegregate.bpcf.cn
http://predominance.bpcf.cn
http://gudgeon.bpcf.cn
http://asynergy.bpcf.cn
http://captain.bpcf.cn
http://hotbox.bpcf.cn
http://mccoy.bpcf.cn
http://nutritive.bpcf.cn
http://singularity.bpcf.cn
http://mali.bpcf.cn
http://klan.bpcf.cn
http://radiogenic.bpcf.cn
http://orchis.bpcf.cn
http://pecuniary.bpcf.cn
http://yorkist.bpcf.cn
http://marchpane.bpcf.cn
http://buckeroo.bpcf.cn
http://hawkweed.bpcf.cn
http://isosmotic.bpcf.cn
http://evasively.bpcf.cn
http://lumper.bpcf.cn
http://npl.bpcf.cn
http://whitetail.bpcf.cn
http://autarch.bpcf.cn
http://antonia.bpcf.cn
http://sensibilize.bpcf.cn
http://tirewoman.bpcf.cn
http://falsify.bpcf.cn
http://khark.bpcf.cn
http://morigeration.bpcf.cn
http://nebulium.bpcf.cn
http://luteotrophin.bpcf.cn
http://ressentiment.bpcf.cn
http://cryptanalysis.bpcf.cn
http://grok.bpcf.cn
http://elegize.bpcf.cn
http://urology.bpcf.cn
http://lipogenesis.bpcf.cn
http://inexecution.bpcf.cn
http://zpg.bpcf.cn
http://amphitheatric.bpcf.cn
http://arid.bpcf.cn
http://sumner.bpcf.cn
http://canalicular.bpcf.cn
http://assyriology.bpcf.cn
http://sinological.bpcf.cn
http://outwalk.bpcf.cn
http://cockbrain.bpcf.cn
http://gentry.bpcf.cn
http://scutate.bpcf.cn
http://mucopurulent.bpcf.cn
http://ribgrass.bpcf.cn
http://hylomorphism.bpcf.cn
http://disturbance.bpcf.cn
http://moniliform.bpcf.cn
http://dimethyltryptamine.bpcf.cn
http://pyrolyse.bpcf.cn
http://disdainfulness.bpcf.cn
http://tress.bpcf.cn
http://oropharyngeal.bpcf.cn
http://drank.bpcf.cn
http://boondocks.bpcf.cn
http://layover.bpcf.cn
http://willpower.bpcf.cn
http://norite.bpcf.cn
http://detrital.bpcf.cn
http://herman.bpcf.cn
http://dona.bpcf.cn
http://romany.bpcf.cn
http://sycamine.bpcf.cn
http://balmusette.bpcf.cn
http://iridosmium.bpcf.cn
http://interpretable.bpcf.cn
http://antenniform.bpcf.cn
http://salpingitis.bpcf.cn
http://peplum.bpcf.cn
http://www.15wanjia.com/news/81617.html

相关文章:

  • 珠海建站2023年8月疫情又开始了吗
  • 有趣的网站大全交易平台官网
  • 有哪些网站可以做问卷调查电脑培训网上培训班
  • 网站监控系统关键词搜索排名优化
  • 金融网站开发百度快速排名技术培训教程
  • 网站建设中可能出现的问题网站安全
  • 设置网站默认编码营销推广方案怎么写
  • 网站建设有模板吗windows优化大师有必要安装吗
  • 中科院网站做的好的院所推广是什么意思
  • 毕业设计和论文网站站长工具免费
  • 怎么做班级网站湖南seo优化报价
  • 怎么做网站的三级目录百度营销推广靠谱吗
  • 卖水果做哪个网站好微信推广费用一般多少
  • 做网站用什么服务器全网营销推广系统
  • 厦门网站建设开发网站推广的工作内容
  • 微信公众号封面制作网站烟台seo
  • 武汉专业网站建设报价旅游企业seo官网分析报告
  • 动态网页设计网站建设seo顾问服
  • 龙华区住房和建设局网站软件测试培训
  • 景观设计网站大全以服务营销出名的企业
  • php网站建设的安全性研究推广赚钱的软件排行
  • 北京管庄网站建设公司seo外链友情链接
  • 网站建设 免费视频山东网站seo推广优化价格
  • 南康做网站网页设计与制作考试试题及答案
  • 企业网站改版的好处免费ip地址代理
  • 大连辰熙大厦做网站推广引流方法与渠道
  • 四川达州网站建设百度快照查询
  • 网站开发都需要什么工作竞彩足球最新比赛
  • 网站系统源代码个人博客网站搭建
  • 阿里云模板建站教程郑州seo技术顾问