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

相关推荐
凌肖战17 分钟前
力扣网C语言编程题:快慢指针来解决 “寻找重复数”
c语言·算法·leetcode
Alfred king13 小时前
面试150 生命游戏
leetcode·游戏·面试·数组
薰衣草233320 小时前
一天两道力扣(1)
算法·leetcode·职场和发展
爱coding的橙子20 小时前
每日算法刷题Day41 6.28:leetcode前缀和2道题,用时1h20min(要加快)
算法·leetcode·职场和发展
前端拿破轮1 天前
不是吧不是吧,leetcode第一题我就做不出来?😭😭😭
后端·算法·leetcode
前端拿破轮1 天前
😭😭😭看到这个快乐数10s,我就知道快乐不属于我了🤪
算法·leetcode·typescript
今天背单词了吗9801 天前
算法学习笔记:4.KMP 算法——从原理到实战,涵盖 LeetCode 与考研 408 例题
笔记·学习·考研·算法·leetcode·kmp算法
hn小菜鸡1 天前
LeetCode 377.组合总和IV
数据结构·算法·leetcode
亮亮爱刷题11 天前
飞往大厂梦之算法提升-7
数据结构·算法·leetcode·动态规划
zmuy11 天前
124. 二叉树中的最大路径和
数据结构·算法·leetcode