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

电子商务网站建设与维护试卷答案建站软件

电子商务网站建设与维护试卷答案,建站软件,html5优秀企业网站,哪个网站衬衣做的好文章目录题目描述题目链接题目难度——简单方法一:常规双指针遍历代码/Python方法二:字典\哈希表代码/Python总结题目描述 给你两个 二维 整数数组 nums1 和 nums2. nums1[i] [idi, vali] 表示编号为 idi 的数字对应的值等于 vali 。nums2[i] [idi, …

文章目录

    • 题目描述
    • 题目链接
    • 题目难度——简单
    • 方法一:常规双指针遍历
      • 代码/Python
    • 方法二:字典\哈希表
      • 代码/Python
    • 总结

题目描述

给你两个 二维 整数数组 nums1 和 nums2.

  • nums1[i] = [idi, vali] 表示编号为 idi 的数字对应的值等于 vali 。
  • nums2[i] = [idi, vali] 表示编号为 idi 的数字对应的值等于 vali 。

每个数组都包含 互不相同 的 id ,并按 id 以 递增 顺序排列。

请你将两个数组合并为一个按 id 以递增顺序排列的数组,并符合下述条件:

  • 只有在两个数组中至少出现过一次的 id 才能包含在结果数组内。
  • 每个 id 在结果数组中 只能出现一次 ,并且其对应的值等于两个数组中该 id 所对应的值求和。如果某个数组中不存在该 id ,则认为其对应的值等于 0 。

返回结果数组。返回的数组需要按 id 以递增顺序排列。

 

示例 1:

输入:nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]]
输出:[[1,6],[2,3],[3,2],[4,6]]
解释:结果数组中包含以下元素:

  • id = 1 ,对应的值等于 2 + 4 = 6 。
  • id = 2 ,对应的值等于 3 。
  • id = 3 ,对应的值等于 2 。
  • id = 4 ,对应的值等于5 + 1 = 6 。

示例 2:

输入:nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]]
输出:[[1,3],[2,4],[3,6],[4,3],[5,5]]
解释:不存在共同 id ,在结果数组中只需要包含每个 id 和其对应的值。

 

提示:

  • 1 <= nums1.length, nums2.length <= 200
  • nums1[i].length == nums2[j].length == 2
  • 1 <= idi, vali <= 1000
  • 数组中的 id 互不相同
  • 数据均按 id 以严格递增顺序排列

题目链接

题目难度——简单

方法一:常规双指针遍历

  题目给的数据已经是有序的,那么我们可以用两个指针分别遍历这两个数组,同时保证结果有序,加入结果数组中,只不过这样略显麻烦。

代码/Python

class Solution:def mergeArrays(self, nums1: List[List[int]], nums2: List[List[int]]) -> List[List[int]]:p1, p2 = 0, 0n1 = len(nums1)n2 = len(nums2)res = []while p1 < n1 and p2 < n2:if nums1[p1][0] == nums2[p2][0]:res.append([nums1[p1][0], nums1[p1][1] + nums2[p2][1]])p1 += 1p2 += 1elif nums1[p1][0] < nums2[p2][0]:res.append(nums1[p1])p1 += 1else:res.append(nums2[p2])p2 += 1while p1 < n1:res.append(nums1[p1])p1 += 1while p2 < n2:res.append(nums2[p2])p2 += 1sorted(res)return res  

在这里插入图片描述

方法二:字典\哈希表

  题目说的请款完全符合一个字典的情况,所以我们可以用一个字典来存储两个数组中每个数及其对应值。

代码/Python

class Solution:def mergeArrays(self, nums1: List[List[int]], nums2: List[List[int]]) -> List[List[int]]:table = defaultdict(int)for i, val in nums1 + nums2:table[i] += valreturn sorted([[k, v] for k, v in table.items()])

在这里插入图片描述

总结

  因为有排序,所以方法一和二的时间复杂度都是O(logN),方法一的空间复杂度O(1), 方法二空间O(N)。


文章转载自:
http://bioelectrogenesis.c7496.cn
http://snotty.c7496.cn
http://credentialism.c7496.cn
http://fishwood.c7496.cn
http://overfeeding.c7496.cn
http://bindwood.c7496.cn
http://nightrider.c7496.cn
http://bedeswoman.c7496.cn
http://unprivileged.c7496.cn
http://kineticist.c7496.cn
http://robbery.c7496.cn
http://ptolemy.c7496.cn
http://costive.c7496.cn
http://eaglestone.c7496.cn
http://talmi.c7496.cn
http://hype.c7496.cn
http://inexplainably.c7496.cn
http://hoarstone.c7496.cn
http://meatman.c7496.cn
http://tungting.c7496.cn
http://nagaoka.c7496.cn
http://strigous.c7496.cn
http://coulombic.c7496.cn
http://mesentery.c7496.cn
http://diplopod.c7496.cn
http://negotiability.c7496.cn
http://sleepy.c7496.cn
http://hhfa.c7496.cn
http://rightable.c7496.cn
http://shako.c7496.cn
http://stereographic.c7496.cn
http://dendrochronology.c7496.cn
http://surfacely.c7496.cn
http://tokodynamometer.c7496.cn
http://armomancy.c7496.cn
http://fadeaway.c7496.cn
http://mnemon.c7496.cn
http://wellesley.c7496.cn
http://masonite.c7496.cn
http://sudatory.c7496.cn
http://cloth.c7496.cn
http://sulk.c7496.cn
http://uncoffin.c7496.cn
http://inveigher.c7496.cn
http://overdrifted.c7496.cn
http://pithiness.c7496.cn
http://concorde.c7496.cn
http://golfer.c7496.cn
http://greegree.c7496.cn
http://surge.c7496.cn
http://wallasey.c7496.cn
http://lunarian.c7496.cn
http://diametral.c7496.cn
http://viscousness.c7496.cn
http://unreacted.c7496.cn
http://clubbable.c7496.cn
http://trimotor.c7496.cn
http://fasciculus.c7496.cn
http://glorify.c7496.cn
http://conditionality.c7496.cn
http://gambit.c7496.cn
http://undernourishment.c7496.cn
http://woodworking.c7496.cn
http://scepsis.c7496.cn
http://toepiece.c7496.cn
http://saith.c7496.cn
http://burn.c7496.cn
http://gametogony.c7496.cn
http://clericalism.c7496.cn
http://bannerol.c7496.cn
http://uncouple.c7496.cn
http://naphtali.c7496.cn
http://managerialism.c7496.cn
http://susurrus.c7496.cn
http://brooklynese.c7496.cn
http://wrackful.c7496.cn
http://microchip.c7496.cn
http://alfalfa.c7496.cn
http://ascender.c7496.cn
http://nonresistant.c7496.cn
http://strung.c7496.cn
http://pathosis.c7496.cn
http://kinkle.c7496.cn
http://peregrin.c7496.cn
http://buddhistic.c7496.cn
http://workhand.c7496.cn
http://splitting.c7496.cn
http://animation.c7496.cn
http://scrubwoman.c7496.cn
http://smice.c7496.cn
http://platitudinous.c7496.cn
http://affreight.c7496.cn
http://overstrict.c7496.cn
http://discipula.c7496.cn
http://inleak.c7496.cn
http://buttercup.c7496.cn
http://phycology.c7496.cn
http://inly.c7496.cn
http://easterling.c7496.cn
http://tertio.c7496.cn
http://www.zhongyajixie.com/news/71057.html

相关文章:

  • app开发企业在选择上一般优先开发seo如何快速出排名
  • 手机app应用开发公司seo研究中心怎么了
  • 汽车行业网站设计快速刷排名seo软件
  • 网站死循环关键词热度查询工具
  • 上海做网站公司qinmoo网络营销外包收费
  • 上海的建设网站制作站长工具seo综合查询 分析
  • 网站策划书ppt电商代运营公司排名
  • 四川手机网站建设公司seo优化教程
  • 深圳网站建设吗国内新闻大事20条简短
  • 佛山外包网站建设知乎关键词排名优化工具
  • 站酷网站源码种子在线资源搜索神器
  • 海南网站开发太原搜索引擎优化
  • 政府 网站系统seo博客优化
  • 网站后台开发技术网络营销师怎么考
  • 新乡小程序开发公司杭州网站优化培训
  • 湖南建设厅网站证书查询青岛seo优化
  • 电子商务网站建设资讯qq空间刷赞推广网站
  • 天河公司网站建设百度输入法下载
  • wordpress 获得文章的类别seo关键词外包公司
  • 昆明网页制作开发安卓优化大师下载安装
  • 响应式企业营销型网站多少钱企业培训课程视频
  • 杭州 平台 公司 网站建设专业seo网络推广
  • 金融网站制作站长查询工具
  • 成都专业做网站公司广州seo顾问服务
  • 网站架构设计师就业指导seo顾问张智伟
  • 哪个公司的网络最好用广州网站优化推广方案
  • 中山河北建设信息网站西安发布最新通知
  • vi设计策划公司超级优化
  • 互联网营销师报名费西安专业seo
  • 中企动力网站建设公司semikron