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

相关推荐
加农炮手Jinx5 小时前
LeetCode 146. LRU Cache 题解
算法·leetcode·力扣
加农炮手Jinx5 小时前
LeetCode 128. Longest Consecutive Sequence 题解
算法·leetcode·力扣
旖-旎5 小时前
递归(汉诺塔问题)(1)
c++·学习·算法·leetcode·深度优先·递归
JAVA学习通5 小时前
励志从零打造LeetCode平台之C端竞赛列表
java·vscode·leetcode·docker·状态模式
莫等闲-6 小时前
代码随想录一刷记录Day31——leetcode56. 合并区间 738.单调递增的数字
数据结构·c++·算法·leetcode
剑挑星河月7 小时前
45.跳跃游戏Ⅱ
数据结构·算法·leetcode
Tisfy7 小时前
LeetCode 3783.整数的镜像距离:数学
数学·算法·leetcode·题解
水蓝烟雨7 小时前
0010.三数之和
数据结构·算法·leetcode
啊哦呃咦唔鱼9 小时前
LeetCode双指针合集
算法·leetcode·职场和发展
alphaTao9 小时前
LeetCode 每日一题 2026/4/13-2026/4/19
算法·leetcode·职场和发展