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

相关推荐
白白白小纯5 小时前
算法篇—反转链表
c语言·数据结构·算法·leetcode
圣保罗的大教堂7 小时前
leetcode 3517. 最小回文排列 I 中等
leetcode
alphaTao10 小时前
LeetCode 每日一题 2026/7/27-2026/8/2
python·算法·leetcode
Hi李耶16 小时前
【LeetCode】9-回文数
算法·leetcode·职场和发展
海绵天哥20 小时前
LeetCode Hot 100 | 链表(下)· 分组翻转与设计(C++ 题解)
c++·leetcode·链表
tkevinjd1 天前
力扣131-分割回文串
算法·leetcode·深度优先
zander2582 天前
LeetCode 78. 子集
算法·leetcode·深度优先
Tisfy2 天前
LeetCode 3014.输入单词需要的最少按键次数 I:遍历 / if-else计算(比纯数学公式写起来麻烦但好想)
数学·算法·leetcode·字符串·题解·贪心
tkevinjd2 天前
力扣239-滑动窗口最大值
算法·leetcode·职场和发展
圣保罗的大教堂2 天前
leetcode 628. 三个数的最大乘积 简单
leetcode