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

相关推荐
skywalker_1116 分钟前
力扣hot100-5(盛最多水的容器),6(三数之和)
算法·leetcode·职场和发展
生信研究猿20 分钟前
leetcode 226.翻转二叉树
算法·leetcode·职场和发展
XWalnut1 小时前
LeetCode刷题 day9
java·算法·leetcode
6Hzlia1 小时前
【Hot 100 刷题计划】 LeetCode 39. 组合总和 | C++ 回溯算法与 startIndex 剪枝
c++·算法·leetcode
宵时待雨1 小时前
优选算法专题1:双指针
数据结构·c++·笔记·算法·leetcode
We་ct2 小时前
LeetCode 172. 阶乘后的零:从暴力到最优,拆解解题核心
开发语言·前端·javascript·算法·leetcode·typescript
老虎06272 小时前
LeetCode热题100 刷题笔记(第五天)双指针法 「 三数之和 」
笔记·算法·leetcode
美式请加冰3 小时前
简单多状态问题
数据结构·算法·leetcode
佑白雪乐3 小时前
<LeetCode>二叉树前/中/后/层遍历**递归&&非递归**
算法·leetcode·深度优先
6Hzlia3 小时前
【Hot 100 刷题计划】 LeetCode 279. 完全平方数 | C++ 动态规划 (完全背包)
c++·leetcode·动态规划