205. Isomorphic Strings

LeetCode - The World's Leading Online Programming Learning Platform

python 复制代码
from collections import defaultdict
class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        mydict1={}
        mydict0={}
        for i in range(len(s)):
            c1=(s[i] not in mydict1)
            c0=(t[i] not in mydict0)
            if c1 and c0:
                mydict1[s[i]]=t[i]
                mydict0[t[i]]=s[i]
            elif (not c0) and (not c1):
                if mydict1[s[i]]!=t[i] or mydict0[t[i]]!=s[i]:
                    return False
            else: return False
        return True

双向map

相关推荐
alphaTao18 分钟前
LeetCode 每日一题 2026/7/13-2026/7/19
算法·leetcode
Hesionberger11 小时前
LeetCode406:重建身高队列精髓解析
开发语言·数据结构·python·算法·leetcode
卡提西亚12 小时前
leetcode-239. 滑动窗口最大值
算法·leetcode·职场和发展
旖-旎12 小时前
LeetCode 494:目标和(动态规划/01背包问题)—— 题解
c++·算法·leetcode·动态规划·01背包
圣保罗的大教堂19 小时前
leetcode 3867. 数对的最大公约数之和 中等
leetcode
To_OC21 小时前
LC 15 三数之和:双指针不难,难的是把去重做对
javascript·算法·leetcode
G.O.G.O.G1 天前
LeetCode SQL 从入门到精通(MySQL)06(上)
数据库·sql·mysql·leetcode
闪电悠米1 天前
力扣hot100-56.合并区间-排序详解
数据结构·算法·leetcode·贪心算法·排序算法
卡提西亚1 天前
leetcode-1438. 绝对差不超过限制的最长连续子数组
算法·leetcode·职场和发展
Java面试题总结1 天前
LeetCode 93.复原IP地址
算法·leetcode·职场和发展·.net