当前位置:网站首页>力扣(LeetCode)205. 同构字符串(2022.07.24)
力扣(LeetCode)205. 同构字符串(2022.07.24)
2022-07-25 13:49:00 【ChaoYue_miku】
给定两个字符串 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 字符组成
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/isomorphic-strings
方法一:哈希表
C++提交内容:
class Solution {
public:
bool isIsomorphic(string s, string t) {
unordered_map<char, char> s2t;
unordered_map<char, char> t2s;
int len = s.length();
for (int i = 0; i < len; ++i) {
char x = s[i], y = t[i];
if ((s2t.count(x) && s2t[x] != y) || (t2s.count(y) && t2s[y] != x)) {
return false;
}
s2t[x] = y;
t2s[y] = x;
}
return true;
}
};
边栏推荐
- Canvas判断内容为空
- Audio and video technology development weekly | 255
- Brush questions - Luogu -p1046 Tao Tao picking apples
- Nodejs link MySQL error: Er_ NOT_ SUPPORTED_ AUTH_ MODEError: ER_ NOT_ SUPPORTED_ AUTH_ MODE
- What problems should SEOER pay attention to when baidu searches and attacks pirated websites?
- mujoco_ Py Chinese document
- Package management apt, dpkg
- 在线问题反馈模块实战(十三):实现多参数分页查询列表
- IM系统-消息流化一些常见问题
- 「数字安全」警惕 NFT的七大骗局
猜你喜欢

The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio

redis集群的三种方式

What is your revenue rank among global developers in 2022?

DNS resolution error during windows unbutu20 lts apt, WGet installation

Brush questions - Luogu -p1161 turn on the light
[email protected] (using password:YES)"/>The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)

2022全球开发者中,你的收入排多少?

What are the ranking strategies for mobile websites, independent apps and websites?

在线问题反馈模块实战(十三):实现多参数分页查询列表

手把手教学Yolov7的搭建及实践
随机推荐
Lesson of C function without brackets
Leetcode 113. 路径总和 II
ES6数组去重 new Set()
mujoco_ Py Chinese document
Leetcode -- addition of four numbers II
Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
stable_ Baselines quick start
sieve of eratosthenes
Brush questions - Luogu -p1035 series summation
@Wrap decorator
What is your revenue rank among global developers in 2022?
安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
[force buckle] 645. Wrong set
@Classmethod decorator
电脑里一辈子都不想删的神仙软件
Excel record macro
What are the ranking strategies for mobile websites, independent apps and websites?
adb通过Wi-Fi连接小米手机
hcip第八天笔记
Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?