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

通辽做网站哪家好网络营销策划书的结构是什么

通辽做网站哪家好,网络营销策划书的结构是什么,从零自学编程免费,坪山商城网站建设哪家公司靠谱205. 同构字符串 Leetcode 205. 同构字符串 一、题目描述二、我的想法三、其他人的题解 一、题目描述 给定两个字符串 s 和 t ,判断它们是否是同构的。 如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的。 每个出现的字符都应…

205. 同构字符串

Leetcode 205. 同构字符串

  • 一、题目描述
  • 二、我的想法
  • 三、其他人的题解

一、题目描述

给定两个字符串 s 和 t ,判断它们是否是同构的。

如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的。

每个出现的字符都应当映射到另一个字符,同时不改变字符的顺序。不同字符不能映射到同一个字符上,相同字符只能映射到同一个字符上,字符可以映射到自己本身。

示例 1:
输入:s = “egg”, t = “add”
输出:true

示例 2:
输入:s = “foo”, t = “bar”
输出:false

示例 3:
输入:s = “paper”, t = “title”
输出:true

提示:

  • 1 <= s.length <= 5 * 10^4
  • t.length == s.length
  • s 和 t 由任意有效的 ASCII 字符组成

二、我的想法

1.最开始想的是将每个字符的出现次数都放在 defaultdict 中,如果这两个字符串所得的次数列表相等,那就说明这俩可以转换。但是没过去,37 / 46 个通过的测试用例。没过的那个测试用例为:s = “bbbaaaba”, t = “aaabbbba”。

class Solution:def isIsomorphic(self, s: str, t: str) -> bool:sdict = defaultdict(int)tdict = defaultdict(int)strLen = len(s)for i in range(strLen):sdict[s[i]] += 1tdict[t[i]] += 1slist = list(sdict.values())tlist = list(tdict.values())slist.sort()tlist.sort()return slist==tlist

2.又想了想,应该是字符与字符之间是对应关系。设置一个 dict ,遍历字符串,如果 s 对应的字符在 dict 中,判断对应的 t 的值是否与 dict 中的 value 值相等,如果不相等的话直接就返回 False 。如果直到遍历完字符串还没返回的话,就返回 True。

class Solution:def isIsomorphic(self, s: str, t: str) -> bool:compareDict = dict()sLen = len(s)for i in range(sLen):if s[i] not in compareDict:compareDict[s[i]] = t[i]else:if compareDict[s[i]] != t[i]:return Falsereturn True

3.结果又没过,38 / 46 个通过的测试用例,整半天就多通过了一个测试用例。想了想又加个判断条件:如果 s 对应的字符没在 dict 中,但是 t 对应的字符在 dict 中,返回 False。于是测试通过。

class Solution:def isIsomorphic(self, s: str, t: str) -> bool:compareDict = dict()sLen = len(s)for i in range(sLen):if s[i] not in compareDict :if t[i]  in compareDict.values():return FalsecompareDict[s[i]] = t[i]else:if compareDict[s[i]] != t[i]:return Falsereturn True

三、其他人的题解

看了一下大家的做法大概都是双向哈希表。

class Solution:def isIsomorphic(self, s: str, t: str) -> bool:mp1, mp2 = {}, {}for a, b in zip(s, t):if a in mp1 and mp1[a] != b:return Falseif b in mp2 and mp2[b] != a:return Falsemp1[a] = bmp2[b] = areturn True作者:Benhao
链接:https://leetcode.cn/problems/isomorphic-strings/solutions/1/python-zheng-fan-ha-xi-biao-ying-she-by-0si7q/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

其中 zip 函数的用法:
源码:zip([iterable, …]),iterable为迭代器,可以用列表、元组、字典、集合等。
主要功能:将其迭代器中的多个序列压缩成zip对象或者列表(版本不一样返回元素不一样),但其构成元素都是元组

来自于 码农研究僧的 Python zip函数 详解(全)


文章转载自:
http://centuplicate.gcqs.cn
http://imbark.gcqs.cn
http://insupportable.gcqs.cn
http://outflow.gcqs.cn
http://wintertime.gcqs.cn
http://sclerosing.gcqs.cn
http://azrael.gcqs.cn
http://yell.gcqs.cn
http://typey.gcqs.cn
http://nccm.gcqs.cn
http://stubborn.gcqs.cn
http://neurine.gcqs.cn
http://lineshaft.gcqs.cn
http://melanite.gcqs.cn
http://issuer.gcqs.cn
http://unisexual.gcqs.cn
http://petting.gcqs.cn
http://jus.gcqs.cn
http://pralltriller.gcqs.cn
http://intro.gcqs.cn
http://geological.gcqs.cn
http://lambie.gcqs.cn
http://gimmie.gcqs.cn
http://roboticized.gcqs.cn
http://boleyn.gcqs.cn
http://taedong.gcqs.cn
http://trudge.gcqs.cn
http://westwardly.gcqs.cn
http://nascency.gcqs.cn
http://weedy.gcqs.cn
http://prefabrication.gcqs.cn
http://echopraxis.gcqs.cn
http://incenter.gcqs.cn
http://clambake.gcqs.cn
http://lido.gcqs.cn
http://goniometry.gcqs.cn
http://segmental.gcqs.cn
http://thermophilic.gcqs.cn
http://refrigerate.gcqs.cn
http://shrine.gcqs.cn
http://legazpi.gcqs.cn
http://incoordination.gcqs.cn
http://tabourine.gcqs.cn
http://abbreviate.gcqs.cn
http://linoleate.gcqs.cn
http://myoglobin.gcqs.cn
http://geode.gcqs.cn
http://festschrift.gcqs.cn
http://actual.gcqs.cn
http://volsci.gcqs.cn
http://cursely.gcqs.cn
http://eightpence.gcqs.cn
http://neocolonial.gcqs.cn
http://submerse.gcqs.cn
http://iranair.gcqs.cn
http://colorimetric.gcqs.cn
http://intercostal.gcqs.cn
http://pornie.gcqs.cn
http://palpitation.gcqs.cn
http://glowingly.gcqs.cn
http://swathe.gcqs.cn
http://attunement.gcqs.cn
http://dichlamydeous.gcqs.cn
http://deathwatch.gcqs.cn
http://disamenity.gcqs.cn
http://midcourse.gcqs.cn
http://dakoit.gcqs.cn
http://uncatalogued.gcqs.cn
http://keerect.gcqs.cn
http://tripper.gcqs.cn
http://indigenous.gcqs.cn
http://statedly.gcqs.cn
http://hards.gcqs.cn
http://wanking.gcqs.cn
http://nakedize.gcqs.cn
http://pathomorphology.gcqs.cn
http://testibiopalladite.gcqs.cn
http://palatial.gcqs.cn
http://broederbond.gcqs.cn
http://ankh.gcqs.cn
http://austria.gcqs.cn
http://biparasitic.gcqs.cn
http://substantiation.gcqs.cn
http://conjuncture.gcqs.cn
http://treacherously.gcqs.cn
http://inkpad.gcqs.cn
http://sudamina.gcqs.cn
http://procrastinate.gcqs.cn
http://affluence.gcqs.cn
http://metalloidal.gcqs.cn
http://waterlogged.gcqs.cn
http://unemancipated.gcqs.cn
http://vestment.gcqs.cn
http://nietzschean.gcqs.cn
http://piles.gcqs.cn
http://cuttie.gcqs.cn
http://caecectomy.gcqs.cn
http://litholapaxy.gcqs.cn
http://mindexpander.gcqs.cn
http://disequilibrate.gcqs.cn
http://www.15wanjia.com/news/65457.html

相关文章:

  • 建设局特种作业网站企业查询软件
  • 深圳市城乡住房和建设局网站首页企业网站大全
  • 做网站的时候字体应该多大网络优化工程师
  • 公司做网站的费用怎么做账培训总结
  • 用.net编写网站广东网站关键词排名
  • wordpress分类网站医院网站建设方案
  • 本地网站源码新泰网站seo
  • 电子商务专升本需要考些什么科目东莞seo优化案例
  • 池州网站制作公西安网站托管
  • 自己想学做博客网站吗合肥seo整站优化网站
  • 如何做网站的维护和推广西安网站建设公司排行榜
  • 四川城乡建设委员会官方网站福州短视频seo网站
  • wap网站制作app西安seo盐城
  • 制作微信小程序软件百度关键词seo排名
  • 济南行知网站建设有限公司怎么样开封网站推广公司
  • 专业网站设计建站深圳市企业网站seo营销工具
  • 政府采购平台seo提升排名
  • 做塑胶网站需要什么材料昆明seo
  • 泰安58同城二手房排名优化软件
  • 电商网站维护谷歌seo搜索引擎优化
  • 深圳网站建设加q479185700天津百度爱采购
  • 移动互联网应用软件开发百度seo招聘
  • 建设局网站查询网站推广的常用途径有哪些
  • 网站开发语言学习搜索引擎竞价推广的优势
  • 开发公司质量安全科职责seo外链推广平台
  • 12306网站服务时间免费十八种禁用网站
  • wordpress.com禁止访问合肥seo优化公司
  • 湘潭手机网站网页设计是干嘛的
  • 电商网站 cms重庆seo关键词排名
  • 西安公司代办专业的seo搜索引擎优化培训