python-leetcode-同构字符串

205. 同构字符串 - 力扣(LeetCode)

python 复制代码
class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False
        
        mapping_s_t = {}
        mapping_t_s = {}
        
        for char_s, char_t in zip(s, t):
            # 检查 s -> t 的映射
            if char_s in mapping_s_t:
                if mapping_s_t[char_s] != char_t:
                    return False
            else:
                mapping_s_t[char_s] = char_t
            
            # 检查 t -> s 的映射
            if char_t in mapping_t_s:
                if mapping_t_s[char_t] != char_s:
                    return False
            else:
                mapping_t_s[char_t] = char_s
        
        return True
相关推荐
88号技师14 分钟前
2025年6月一区-田忌赛马优化算法Tianji’s horse racing optimization-附Matlab免费代码
开发语言·算法·matlab·优化算法
ゞ 正在缓冲99%…42 分钟前
leetcode918.环形子数组的最大和
数据结构·算法·leetcode·动态规划
Kaltistss2 小时前
98.验证二叉搜索树
算法·leetcode·职场和发展
知己如祭2 小时前
图论基础(DFS、BFS、拓扑排序)
算法
mit6.8242 小时前
[Cyclone] 哈希算法 | SIMD优化哈希计算 | 大数运算 (Int类)
算法·哈希算法
c++bug2 小时前
动态规划VS记忆化搜索(2)
算法·动态规划
哪 吒2 小时前
2025B卷 - 华为OD机试七日集训第5期 - 按算法分类,由易到难,循序渐进,玩转OD(Python/JS/C/C++)
python·算法·华为od·华为od机试·2025b卷
军训猫猫头2 小时前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
success3 小时前
【爆刷力扣-数组】二分查找 及 衍生题型
算法
Orlando cron3 小时前
数据结构入门:链表
数据结构·算法·链表