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

相关推荐
闫铁娃2 小时前
二分解题的奇技淫巧都有哪些,你还不会吗?
c语言·数据结构·c++·算法·leetcode
CV工程师小林3 小时前
【算法】DFS 系列之 穷举/暴搜/深搜/回溯/剪枝(下篇)
数据结构·c++·算法·leetcode·深度优先·剪枝
OLDERHARD4 小时前
Java - LeetCode面试经典150题 - 矩阵 (四)
java·leetcode·面试
Themberfue4 小时前
基础算法之双指针--Java实现(下)--LeetCode题解:有效三角形的个数-查找总价格为目标值的两个商品-三数之和-四数之和
java·开发语言·学习·算法·leetcode·双指针
陈序缘5 小时前
LeetCode讲解篇之322. 零钱兑换
算法·leetcode·职场和发展
-$_$-5 小时前
【LeetCode HOT 100】详细题解之二叉树篇
数据结构·算法·leetcode
大白飞飞5 小时前
力扣203.移除链表元素
算法·leetcode·链表
夜雨翦春韭6 小时前
【代码随想录Day29】贪心算法Part03
java·数据结构·算法·leetcode·贪心算法
Tisfy6 小时前
LeetCode 1928.规定时间内到达终点的最小花费:动态规划
算法·leetcode·动态规划·
Mopes__8 小时前
Python | Leetcode Python题解之第461题汉明距离
python·leetcode·题解