C++ | Leetcode C++题解之第205题同构字符串

题目:

题解:

cpp 复制代码
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;
    }
};
相关推荐
夏鹏今天学习了吗1 小时前
【LeetCode热题100(83/100)】最长递增子序列
算法·leetcode·职场和发展
暮色_年华1 小时前
随想 2:对比 linux内核侵入式链表和 STL 非侵入链表
linux·c++·链表
w-w0w-w2 小时前
C++模板参数与特化全解析
开发语言·c++
AlenTech2 小时前
155. 最小栈 - 力扣(LeetCode)
算法·leetcode·职场和发展
大锦终3 小时前
递归回溯综合练习
c++·算法·深度优先
晚风吹长发3 小时前
初步了解Linux中的动静态库及其制作和使用
linux·运维·服务器·数据结构·c++·后端·算法
坚持不懈的大白4 小时前
Leetcode学习笔记
笔记·学习·leetcode
风之歌曲4 小时前
c++高精度模板
c++·算法·矩阵
crescent_悦4 小时前
C++:Find Coins
c++
嵌入式进阶行者4 小时前
【算法】深度优先搜索实例:华为OD机考双机位A卷- 中庸行者
c++·算法·华为od·深度优先