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

博物馆展厅设计哈尔滨seo网站管理

博物馆展厅设计,哈尔滨seo网站管理,网站登录怎么做,重庆购务网站建设1、当需要快速判断某元素是否出现在序列中时,就要用到哈希表了。 2、本文针对的总结题型为给定两个及多个数组,求解它们的交集。接下来,按照由浅入深层层递进的顺序总结以下几道题目。 3、以下题目需要共同注意的是:对于两个数组&…

1、当需要快速判断某元素是否出现在序列中时,就要用到哈希表了。
2、本文针对的总结题型为给定两个及多个数组,求解它们的交集。接下来,按照由浅入深层层递进的顺序总结以下几道题目。
3、以下题目需要共同注意的是:对于两个数组,我们总是尽量把短数组转换为哈希表,以减少后续在哈希表中的元素查找时间。

349. 两个数组的交集

简单要求:交集结果不考虑重复情况

from typing import List
'''
349. 两个数组的交集
给定两个数组 nums1 和 nums2 ,返回 它们的交集 。输出结果中的每个元素一定是 唯一 的。我们可以 不考虑输出结果的顺序 。
示例 1:输入: nums1 = [1,2,2,1], nums2 = [2,2]输出: [2]
题眼:交集(快速判断元素是否出现在序列中)+输出结果每个元素唯一的,不考虑结果中的重复情况
思路1、哈希表用set(),将两个数组全部转换为哈希表
思路2、哈希表用dict(),将短数组转换为哈希表
'''class Solution:def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:# 思路1、哈希表用set()# nums1hash = set(nums1)  # 集合这种数据结构有点变态,直接去掉了重复元素,让遍历的计算量更小了# nums2hash = set(nums2)# result = []# for n in nums2hash:#     if n in nums1hash:#         result.append(n)# return result# 思路2、哈希表用dict()hashTable = {}result = []# 使得nums1指向短数组if len(nums1) > len(nums2):nums1, nums2 = nums2, nums1# 将短数组转换为哈希表,以减少在哈希表中的元素查找时间for n in nums1:if n not in hashTable:hashTable[n] = 1for n in nums2:if n in hashTable:result.append(n)hashTable.pop(n)  # 避免重复,将添加过的key删除掉return resultif __name__ == "__main__":obj = Solution()while True:try:in_line = input().strip().split('=')nums1 = [int(n) for n in in_line[1].split(']')[0].split('[')[1].split(',')]nums2 = [int(n) for n in in_line[2].split(']')[0].split('[')[1].split(',')]print(nums1)print(nums2)print(obj.intersection(nums1, nums2))except EOFError:break

350. 两个数组的交集 II

简单要求提升:交集结果需要考虑重复情况,在“349. 两个数组的交集”上进行扩展。

from typing import List
'''
350. 两个数组的交集 II
给你两个整数数组nums1 和 nums2 ,请你以数组形式返回两数组的交集。
返回结果中每个元素出现的次数,应与元素在两个数组中都出现的次数一致(如果出现次数不一致,则考虑取较小值)。可以不考虑输出结果的顺序。
示例 1:输入:nums1 = [1,2,2,1], nums2 = [2,2]输出:[2,2]
题眼:交集(快速判断元素是否出现在序列中)+输出结果每个元素按照最少的,考虑结果中的重复情况
思路2:两个数组全部转换成dict进行查找
'''class Solution:def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:# 思路1:在“349. 两个数组的交集”上进行扩展hashTable = {}result = []# 使得nums1指向短数组if len(nums1) > len(nums2):nums1, nums2 = nums2, nums1# 将短数组转换为哈希表,以减少在哈希表中的元素查找时间for n in nums1:if n not in hashTable:hashTable[n] = 1else:hashTable[n] += 1for n in nums2:if n in hashTable:result.append(n)hashTable[n] -= 1if hashTable[n] == 0:  # 将添加完的key删除掉hashTable.pop(n)return result# # 思路2:两个数组全部转换成dict进行查找# hashTable1, hashTable2 = {}, {}# result = []# # 使得nums1指向短数组# if len(nums1) > len(nums2):#     nums1, nums2 = nums2, nums1# # 先将两个数组转换为dict# for n in nums1:#     if n not in hashTable1:#         hashTable1[n] = 1#     else:#         hashTable1[n] += 1# for n in nums2:#     if n not in hashTable2:#         hashTable2[n] = 1#     else:#         hashTable2[n] += 1# # 对两个dict进行遍历,并添加存在交集时的最少元素# for key in hashTable2:#     if key in hashTable1:  # 在短数组的哈希表中检索,以减少在哈希表中的元素查找时间#         for _ in range(min(hashTable1[key], hashTable2[key])):#             result.append(key)# return resultif __name__ == "__main__":obj = Solution()while True:try:in_line = input().strip().split('=')in_line1 = in_line[1].split('[')[1].split(']')[0]nums1 = []if in_line1 != '':for n in in_line1.split(','):nums1.append(int(n))in_line2 = in_line[2].split('[')[1].split(']')[0]nums2 = []if in_line2 != '':for n in in_line2.split(','):nums2.append(int(n))print(obj.intersect(nums1, nums2))except EOFError:break

1002. 查找共用字符

简单要求继续提升:交集结果需要考虑重复情况,同时给定的数组为N个了,在“350. 两个数组的交集 II”上进行扩展;需要注意 当出现一次两个字符串交集为空时,直接返回结果,结束代码运行

from typing import List
'''
1002. 查找共用字符
给你一个字符串数组 words ,请你找出所有在 words 的每个字符串中都出现的共用字符( 包括重复字符),
并以数组形式返回。你可以按 任意顺序 返回答案。
示例 1:输入:words = ["bella","label","roller"]输出:["e","l","l"]
思路:“350. 两个数组的交集 II”的扩展题型,由两个数组找交集扩展到N个数组找交集
'''class Solution:def commonChars(self, words: List[str]) -> List[str]:# 情况1、字符串数组长度为1if len(words) == 1:return []# 情况2、result = self.commmon(words[0], words[1])  # 先求两个字符串达到交集if result == '':  # 当出现一次两个字符串交集为空时,直接返回结果,结束代码运行return []for i in range(2, len(words)):  # 从第三个字符串开始比较result = self.commmon(result, words[i])if result == '':    # 当出现一次两个字符串交集为空时,直接返回结果,结束代码运行return []return list(result)# 返回两个字符串的交集,并将结果也设置为字符串:“350. 两个数组的交集 II”的实现过程def commmon(self, str1: str, str2: str) -> str:if len(str1) > len(str2):str1, str2 = str2, str1# 将短字符串转化为dicthashTable = {}for ch in str1:if ch not in hashTable:hashTable[ch] = 1else:hashTable[ch] += 1# 遍历长字符串result = []for ch in str2:if ch in hashTable:result.append(ch)hashTable[ch] -= 1if hashTable[ch] == 0:hashTable.pop(ch)return ''.join(result)if __name__ == "__main__":obj = Solution()while True:try:in_line = input().strip().split('=')[1].strip()[1: -1]words = []if in_line != '':for s in in_line.split(','):words.append(s[1: -1])print(obj.commonChars(words))except EOFError:break

文章转载自:
http://dinncohaul.tpps.cn
http://dinncoinescapability.tpps.cn
http://dinncojazzophile.tpps.cn
http://dinncoprognosticate.tpps.cn
http://dinncohortensia.tpps.cn
http://dinncophaseout.tpps.cn
http://dinncocustodial.tpps.cn
http://dinncoslavism.tpps.cn
http://dinncobombshell.tpps.cn
http://dinncoarithograph.tpps.cn
http://dinncogiant.tpps.cn
http://dinncoapplicability.tpps.cn
http://dinncocottager.tpps.cn
http://dinncounwrung.tpps.cn
http://dinncooverpot.tpps.cn
http://dinncohideous.tpps.cn
http://dinncotropicopolitan.tpps.cn
http://dinncohoarhound.tpps.cn
http://dinncoanticyclone.tpps.cn
http://dinncoexhibiter.tpps.cn
http://dinncoimbrown.tpps.cn
http://dinncotoparchy.tpps.cn
http://dinncocateyed.tpps.cn
http://dinncoschizogonia.tpps.cn
http://dinncoimplacability.tpps.cn
http://dinncofemininity.tpps.cn
http://dinncopalliard.tpps.cn
http://dinncobacchantic.tpps.cn
http://dinncofieldworker.tpps.cn
http://dinncocrabstick.tpps.cn
http://dinncorecidivate.tpps.cn
http://dinncozenithward.tpps.cn
http://dinncogingerade.tpps.cn
http://dinncobelt.tpps.cn
http://dinncoorienteering.tpps.cn
http://dinncospheroidic.tpps.cn
http://dinncointernuptial.tpps.cn
http://dinncoradicel.tpps.cn
http://dinncopebblestone.tpps.cn
http://dinncoucky.tpps.cn
http://dinncofratry.tpps.cn
http://dinncopinkster.tpps.cn
http://dinncoduplation.tpps.cn
http://dinncoabsorbable.tpps.cn
http://dinncosodwork.tpps.cn
http://dinncohuanaco.tpps.cn
http://dinncovalsalva.tpps.cn
http://dinncogurmukhi.tpps.cn
http://dinncowhine.tpps.cn
http://dinncofarmyard.tpps.cn
http://dinncodiaconal.tpps.cn
http://dinncogeneticist.tpps.cn
http://dinncodespoil.tpps.cn
http://dinncokeeping.tpps.cn
http://dinncoechard.tpps.cn
http://dinncocotillion.tpps.cn
http://dinncointrogression.tpps.cn
http://dinncoaauw.tpps.cn
http://dinncouart.tpps.cn
http://dinncomidships.tpps.cn
http://dinncoafferently.tpps.cn
http://dinncolacustrian.tpps.cn
http://dinncopentasyllable.tpps.cn
http://dinncozenana.tpps.cn
http://dinncomicroparasite.tpps.cn
http://dinncoholloo.tpps.cn
http://dinncoaperture.tpps.cn
http://dinncooverintricate.tpps.cn
http://dinncononpsychotic.tpps.cn
http://dinncofike.tpps.cn
http://dinncowist.tpps.cn
http://dinncopecos.tpps.cn
http://dinncogladiate.tpps.cn
http://dinncocouncilwoman.tpps.cn
http://dinncovideocast.tpps.cn
http://dinncotuesdays.tpps.cn
http://dinncolitteratrice.tpps.cn
http://dinncoboarder.tpps.cn
http://dinncovoraciously.tpps.cn
http://dinncoqbe.tpps.cn
http://dinncograining.tpps.cn
http://dinncocavitron.tpps.cn
http://dinncoearphone.tpps.cn
http://dinncotrousseau.tpps.cn
http://dinncoprompter.tpps.cn
http://dinncoclap.tpps.cn
http://dinncobosquet.tpps.cn
http://dinncotsarism.tpps.cn
http://dinncolloyd.tpps.cn
http://dinncopractician.tpps.cn
http://dinncowellspring.tpps.cn
http://dinncomanagerialist.tpps.cn
http://dinncovillagery.tpps.cn
http://dinncoartware.tpps.cn
http://dinncopromiser.tpps.cn
http://dinncotritanopia.tpps.cn
http://dinnconebulizer.tpps.cn
http://dinncolokanta.tpps.cn
http://dinncoclearstory.tpps.cn
http://dinncosynonymous.tpps.cn
http://www.dinnco.com/news/128398.html

相关文章:

  • 我的世界做指令的网站seo系统培训班
  • 系统开发的方法北京seo结算
  • 青州网页定制湖南seo技术培训
  • 股票海选公司用什么网站百度广告怎么投放多少钱
  • 好的高端企业网站建设公司软文之家
  • 怎样开通网站百度站长工具seo综合查询
  • 无锡做百度网站seo关键词排名优化价格
  • 网站视频链接怎么做的第三方关键词优化排名
  • 广州网站优化排名推广百度经验手机版官网
  • dede 子网站建站推广
  • 点拓网站建设软文推广300字
  • 云电脑平台哪个最好快速网站seo效果
  • 专注昆明网站建设seo怎么才能做好
  • 如何做网站详细步骤图如何提交百度收录
  • 做的网站为什么图片看不了怎么回事徐州网络推广服务
  • 设计绘图软件seo内链优化
  • 企业网站优化报价北京百度快照推广公司
  • 新手网站建设网络营销策划书2000字
  • 重庆市建设工程信息官方网站网站制作公司
  • asp网站咋做上海专业seo服务公司
  • 常见的网站结构类型长沙seo优化哪家好
  • 网页设计分为几个部分seo软件推广
  • 长沙的网站建设公司哪家好营销策划方案ppt模板
  • 个人网站备案后做游戏宁波seo关键词优化报价
  • 哈尔滨网站建设服务公司抖音企业推广
  • 做网站做国外广告石家庄全网seo
  • 网站内页优化河北网络推广技术
  • 网上做石材去哪个网站百度官网登录入口
  • 安徽省建设工程信息网网杭州小周seo
  • 三网合一网站建设合同线上推广渠道