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

相关推荐
过期动态9 小时前
【LeetCode 热题 100】盛最多水的容器
java·数据结构·spring boot·算法·leetcode·spring cloud·职场和发展
凌波粒9 小时前
LeetCode--700.二叉搜索树中的搜索(二叉树)
算法·leetcode·职场和发展
洛水水9 小时前
【力扣100题】58.轮转数组
算法·leetcode
风筝在晴天搁浅10 小时前
阿里 LeetCode 876.链表的中间节点
算法·leetcode·链表
玖釉-10 小时前
二叉树展开为链表:从先序遍历到原地指针重排
c++·windows·算法·leetcode·链表
洛水水10 小时前
【力扣100题】52.最小路径和
算法·leetcode
圣保罗的大教堂11 小时前
leetcode 3043. 最长公共前缀的长度 中等
leetcode
菜菜的顾清寒14 小时前
力扣HOT100(34)图论-岛屿数量
算法·leetcode·图论
圣保罗的大教堂14 小时前
leetcode 2657. 找到两个数组的前缀公共数组 中等
leetcode
洛水水14 小时前
【力扣100题】57.合并区间
算法·leetcode