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

相关推荐
穿条秋裤到处跑1 小时前
每日一道leetcode(2026.04.29):二维网格图中探测环
算法·leetcode·职场和发展
水蓝烟雨7 小时前
1931. 用三种不同颜色为网格涂色
算法·leetcode
leoufung9 小时前
LeetCode 76:Minimum Window Substring 题解与滑动窗口思维详解
算法·leetcode·职场和发展
风筝在晴天搁浅10 小时前
LeetCode 92.反转链表Ⅱ
算法·leetcode·链表
普贤莲花14 小时前
【2026年第18周---写于20260501】---舍得
程序人生·算法·leetcode
m0_6294947314 小时前
LeetCode 热题 100-----16.除了自身以外数组的乘积
数据结构·算法·leetcode
We་ct15 小时前
LeetCode 97. 交错字符串:动态规划详解
前端·算法·leetcode·typescript·动态规划
无敌昊哥战神15 小时前
【LeetCode 37】解数独 (Sudoku Solver) —— 回溯法详解 (Python/C/C++)
c语言·c++·python·算法·leetcode
风筝在晴天搁浅15 小时前
LeetCode 162.寻找峰值
算法·leetcode
罗超驿16 小时前
双指针算法经典案例:LeetCode 283. 移动零(Java详解)
java·算法·leetcode