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

相关推荐
yaoh.wang18 小时前
力扣(LeetCode) 13: 罗马数字转整数 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
sin_hielo21 小时前
leetcode 2110
数据结构·算法·leetcode
麦格芬2301 天前
LeetCode 763 划分字母区间
算法·leetcode·职场和发展
月明长歌1 天前
【码道初阶】【LeetCode 110】平衡二叉树:如何用一个“Magic Number”将复杂度从O(N²)降为 O(N)?
linux·算法·leetcode
yaoh.wang1 天前
力扣(LeetCode) 14: 最长公共前缀 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
埃伊蟹黄面1 天前
算法 --- hash
数据结构·c++·算法·leetcode
ywwwwwwv1 天前
力扣139
算法·leetcode·职场和发展
黛色正浓1 天前
leetCode-热题100-哈希合集(JavaScript)
javascript·leetcode·哈希算法
smj2302_796826521 天前
解决leetcode第3777题使子字符串变交替的最少删除次数
python·算法·leetcode
Tisfy1 天前
LeetCode 2110.股票平滑下跌阶段的数目:数学(一次遍历)
数学·算法·leetcode·题解