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

相关推荐
我搞slam2 小时前
有效的括号--leetcode
linux·算法·leetcode
ゞ 正在缓冲99%…4 小时前
leetcode1312.让字符串成为回文串的最少插入次数
数据结构·算法·leetcode·动态规划·记忆化搜索
别学LeetCode6 小时前
#leetcode#
leetcode
Tisfy7 小时前
LeetCode 3289.数字小镇中的捣蛋鬼:哈希表O(n)空间 / 位运算O(1)空间
算法·leetcode·散列表·题解·位运算·哈希表
一匹电信狗8 小时前
【牛客CM11】链表分割
c语言·开发语言·数据结构·c++·算法·leetcode·stl
L_090710 小时前
【Algorithm】Day-10
c++·算法·leetcode
Swift社区12 小时前
LeetCode 412 - Fizz Buzz
算法·leetcode·职场和发展
小年糕是糕手12 小时前
【C/C++刷题集】二叉树算法题(一)
c语言·数据结构·c++·算法·leetcode·学习方法·改行学it
Dream it possible!1 天前
LeetCode 面试经典 150_链表_旋转链表(64_61_C++_中等)
c++·leetcode·链表·面试
坚持编程的菜鸟1 天前
LeetCode每日一题——Pow(x, n)
c语言·算法·leetcode