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
相关推荐
2401_8812444019 分钟前
vector的用法
算法
W说编程30 分钟前
算法导论第三章:数据结构艺术与高效实现
c语言·数据结构·算法
hn小菜鸡38 分钟前
LeetCode 2529.正整数和负整数的最大计数
java·算法·leetcode
灏瀚星空1 小时前
高频交易技术:订单簿分析与低延迟架构——从Level 2数据挖掘到FPGA硬件加速的全链路解决方案
人工智能·python·算法·信息可视化·fpga开发·架构·数据挖掘
hn小菜鸡1 小时前
LeetCode 2917.找出数组中的K-or值
数据结构·算法·leetcode
Once_day2 小时前
代码训练LeetCode(34)文本左右对齐
算法·leetcode·c
zhuiQiuMX2 小时前
SQL力扣
数据库·sql·leetcode
tony3652 小时前
强化学习 A2C算法
人工智能·算法
Tess_Blingbling2 小时前
力扣Hoot100 第一天 | 哈希3题
leetcode·哈希算法·散列表