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

相关推荐
y = xⁿ2 小时前
20天速通LeetCode day07:前缀和
数据结构·算法·leetcode
小雅痞2 小时前
[Java][Leetcode hard] 42. 接雨水
java·开发语言·leetcode
北顾笙9804 小时前
day26-数据结构力扣
数据结构·算法·leetcode
故事和你914 小时前
洛谷-数据结构1-2-二叉树1
开发语言·数据结构·c++·算法·leetcode·动态规划·图论
_日拱一卒4 小时前
LeetCode:19删除链表的倒数第N个节点
算法·leetcode·链表
y = xⁿ5 小时前
20天速通LeetCode day08:关于栈
算法·leetcode·职场和发展
XWalnut5 小时前
LeetCode刷题 day13
数据结构·算法·leetcode
im_AMBER7 小时前
Leetcode 158 数组中的第K个最大元素 | 查找和最小的 K 对数字
javascript·数据结构·算法·leetcode·
脱氧核糖核酸__7 小时前
LeetCode热题100——48.旋转图像(题解+答案+要点)
c++·算法·leetcode
木井巳7 小时前
【递归算法】字母大小写全排列
java·算法·leetcode·决策树·深度优先