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

相关推荐
夏鹏今天学习了吗6 小时前
【LeetCode热题100(83/100)】最长递增子序列
算法·leetcode·职场和发展
AlenTech7 小时前
155. 最小栈 - 力扣(LeetCode)
算法·leetcode·职场和发展
坚持不懈的大白9 小时前
Leetcode学习笔记
笔记·学习·leetcode
Tisfy10 小时前
LeetCode 3047.求交集区域内的最大正方形面积:2层循环暴力枚举
算法·leetcode·题解·模拟·枚举·几何
栈与堆11 小时前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
鹿角片ljp12 小时前
力扣7.整数反转-从基础到边界条件
算法·leetcode·职场和发展
java修仙传12 小时前
力扣hot100:前K个高频元素
算法·leetcode·职场和发展
爱编码的傅同学14 小时前
【今日算法】Leetcode 581.最短无序连续子数组 和 42.接雨水
数据结构·算法·leetcode
YuTaoShao15 小时前
【LeetCode 每日一题】2053. 数组中第 K 个独一无二的字符串
算法·leetcode·职场和发展
毅炼16 小时前
hot100打卡——day09
java·leetcode