当前位置:网站首页>205. 同构字符串
205. 同构字符串
2022-07-01 03:23:00 【Sun_Sky_Sea】
205. 同构字符串
原始题目链接:https://leetcode.cn/problems/isomorphic-strings/
给定两个字符串 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 * 104
t.length == s.length
s 和 t 由任意有效的 ASCII 字符组成
解题思路:
使用两个哈希表,key是当前字符串的字符,value是对方字符串的字符。
代码实现:
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
d1, d2 = {
}, {
}
for i in range(len(s)):
if ((s[i] in d1 and d1[s[i]] != t[i]) or (t[i] in d2 and d2[t[i]] != s[i])):
return False
d1[s[i]] = t[i]
d2[t[i]] = s[i]
return True
边栏推荐
- Detailed list of errors related to twincat3 ads of Beifu
- Nacos
- Listener listener
- 网页不能右键 F12 查看源代码解决方案
- Avalanche problem and the use of sentinel
- Binary tree god level traversal: Morris traversal
- Research on target recognition and tracking based on 3D laser point cloud
- Implement pow (x, n) function
- idea插件备份表
- Ouc2021 autumn - Software Engineering - end of term (recall version)
猜你喜欢

Ctfshow blasting WP

Jeecgboot output log, how to use @slf4j

Idea plug-in backup table

FCN全卷积网络理解及代码实现(来自pytorch官方实现)

Appium自动化测试基础--补充:C/S架构和B/S架构说明

pytorch nn.AdaptiveAvgPool2d(1)

Listener listener

Ultimate dolls 2.0 | encapsulation of cloud native delivery

后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动

BluePrism注册下载并安装-RPA第一章
随机推荐
Data exchange JSON
JS daily development tips (continuous update)
Pyramid scene parsing network [pspnet] thesis reading
Depth first traversal of C implementation Diagram -- non recursive code
[daily training] 1175 Prime permutation
TEC: Knowledge Graph Embedding with Triple Context
谷粒学院微信扫码登录过程记录以及bug解决
Golang multi graph generation gif
Take you through a circuit board, from design to production (dry goods)
bootsrap中的栅格系统
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
Addition without addition, subtraction, multiplication and division
Appium fundamentals of automated testing - basic principles of appium
数据库中COMMENT关键字的使用
Valentine's Day is nothing.
Ctfshow blasting WP
Leetcode 128 longest continuous sequence (hash set)
服务器渲染技术jsp
过滤器 Filter
Database DDL (data definition language) knowledge points