当前位置:网站首页>力扣(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;
}
};
边栏推荐
- 运动豪华还是安全豪华?亚洲龙与沃尔沃S60该入手哪款?
- uniapp处理后台传输图片
- Pycharm cannot input Chinese solution
- 0720RHCSA
- Framework package merge script
- 【Platform IO编译Hifive1-revB】*** [.pio\build\hifive1-revb\src\setupGPIO.o] Error 1的解决办法
- [force buckle] 645. Wrong set
- Vscode plug-in development
- AQS of concurrent programming
- ADB connects to Xiaomi mobile phone via Wi Fi
猜你喜欢

window unbutu20 LTS apt,wget 安装时 DNS 解析错误

Immortal software in the computer that I don't want to delete all my life

2022年下半年软考信息安全工程师如何备考?

0716RHCSA

包管理 apt,dpkg

2022年下半年软考初级程序员备考

Leetcode202 --- Happy number

刷题-洛谷-P1075 质因数分解

Excel record macro

How can information security engineers prepare for the soft exam in the second half of 2022?
随机推荐
G027-op-ins-rhel-04 RedHat openstack creates a customized qcow2 format image
DNS resolution error during windows unbutu20 lts apt, WGet installation
埃拉托斯特尼筛法
adb通过Wi-Fi连接小米手机
Discussion on principle and application technology of MLIR
mujoco_py中文文档
ES6数组去重 new Set()
ES6 array de duplication new set()
包管理 apt,dpkg
0716RHCSA
I2C can also be powered on by bus!
sieve of eratosthenes
Canvas judgment content is empty
Install oh my Zsh
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
「数字安全」警惕 NFT的七大骗局
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
Explain the precision of floating point numbers in detail
嵌入式代码如何进行重构?
Namespaces and libraries