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
相关推荐
张张努力变强14 分钟前
C++ STL string 类:常用接口 + auto + 范围 for全攻略,字符串操作效率拉满
开发语言·数据结构·c++·算法·stl
万岳科技系统开发15 分钟前
食堂采购系统源码库存扣减算法与并发控制实现详解
java·前端·数据库·算法
张登杰踩20 分钟前
MCR ALS 多元曲线分辨算法详解
算法
YuTaoShao29 分钟前
【LeetCode 每日一题】3634. 使数组平衡的最少移除数目——(解法一)排序+滑动窗口
算法·leetcode·排序算法
波波00737 分钟前
每日一题:.NET 的 GC是如何分代工作的?
算法·.net·gc
HY小宝F41 分钟前
职场沟通的深层智慧:从对抗到协作的自我修炼
职场和发展
风暴之零1 小时前
变点检测算法PELT
算法
深鱼~1 小时前
视觉算法性能翻倍:ops-cv经典算子的昇腾适配指南
算法·cann
李斯啦果1 小时前
【PTA】L1-019 谁先倒
数据结构·算法
梵刹古音1 小时前
【C语言】 指针基础与定义
c语言·开发语言·算法