当前位置:网站首页>205. isomorphic string
205. isomorphic string
2022-07-01 03:43:00 【Sun_ Sky_ Sea】
205. Isomorphic Strings
Original title link :https://leetcode.cn/problems/isomorphic-strings/
Given two strings s and t , Judge whether they are isomorphic .
If s The characters in can be replaced according to some mapping relationship t , So these two strings are isomorphic .
Every character that appears should be mapped to another character , Without changing the order of characters . Different characters cannot be mapped to the same character , The same character can only be mapped to the same character , Characters can be mapped to themselves .
Example 1:
Input :s = “egg”, t = “add”
Output :true
Example 2:
Input :s = “foo”, t = “bar”
Output :false
Example 3:
Input :s = “paper”, t = “title”
Output :true
Tips :
1 <= s.length <= 5 * 104
t.length == s.length
s and t By any valid ASCII Character composition
Their thinking :
Use two hash tables ,key Is the character of the current string ,value Is the character of the opposite string .
Code implementation :
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
边栏推荐
- Md5sum operation
- 用小程序的技术优势发展产业互联网
- Golang multi graph generation gif
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
- Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
- 168. Excel表列名称
- 数据库DDL(Data Definition Language,数据定义语言)知识点
- 4、【WebGIS实战】软件操作篇——数据导入及处理
- Use of comment keyword in database
猜你喜欢

Test function in pychram
![[TA frost wolf \u may- hundred people plan] 1.3 secret of texture](/img/dc/ce2819258632cdcf2e130a4c05600e.png)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture

Bilinear upsampling and f.upsample in pytorch_ bilinear

Develop industrial Internet with the technical advantages of small programs

Use of comment keyword in database

Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)

Cookie&Session

LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表

Download and installation configuration of cygwin

pytorch nn. AdaptiveAvgPool2d(1)
随机推荐
在 C 中声明函数之前调用函数会发生什么?
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
Finally in promise
Include() of array
Split(), split(), slice(), can't you tell?
Thread data sharing and security -threadlocal
multiple linear regression
Learning notes for introduction to C language multithreaded programming
谷粒学院微信扫码登录过程记录以及bug解决
JS daily development tips (continuous update)
Sort linked list (merge sort)
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
Golang multi graph generation gif
10、Scanner. Next() cannot read spaces /indexof -1
389. 找不同
深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
Appium自动化测试基础 — APPium基本原理
Develop industrial Internet with the technical advantages of small programs
Addition without addition, subtraction, multiplication and division
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理