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 小时前
CodeTop Top 300 热门题目2-最长回文子串
开发语言·人工智能·python·算法·leetcode
_深海凉_10 小时前
LeetCode热题100-在排序数组中查找元素的第一个和最后一个位置
算法·leetcode·职场和发展
北顾笙98010 小时前
day28-数据结构力扣
数据结构·算法·leetcode
米粒110 小时前
力扣算法刷题 Day 48(单调栈)
算法·leetcode·职场和发展
Chase_______12 小时前
LeetCode 1456:定长子串中元音的最大数目
算法·leetcode
6Hzlia12 小时前
【Hot 100 刷题计划】 LeetCode 84. 柱状图中最大的矩形 | C++ 两次单调栈基础扫法
c++·算法·leetcode
6Hzlia13 小时前
【Hot 100 刷题计划】 LeetCode 416. 分割等和子集 | C++ 0-1背包 1D空间极致优化
c++·算法·leetcode
穿条秋裤到处跑13 小时前
每日一道leetcode(2026.04.21):执行交换操作后的最小汉明距离
java·算法·leetcode
Tina学编程13 小时前
算法训练Day10 | LeetCode 169 多数元素
算法·leetcode
sheeta199814 小时前
LeetCode 每日一题笔记 日期:2026.04.22 题目:2452. 距离字典两次编辑以内的单词
笔记·算法·leetcode