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

相关推荐
YGGP9 小时前
【Golang】LeetCode 5. 最长回文子串
算法·leetcode
历程里程碑10 小时前
滑动窗口解法:无重复字符最长子串
数据结构·c++·算法·leetcode·职场和发展·eclipse·哈希算法
youngee1111 小时前
hot100-55有效的括号
算法·leetcode·职场和发展
YGGP13 小时前
【Golang】LeetCode 72. 编辑距离
算法·leetcode
YGGP13 小时前
【Golang】LeetCode 62. 不同路径
算法·leetcode
努力学算法的蒟蒻14 小时前
day47(12.28)——leetcode面试经典150
算法·leetcode·面试
iAkuya15 小时前
(leetcode)力扣100 26环状链表2(双指针)
算法·leetcode·链表
sin_hielo15 小时前
leetcode 2402(双堆模拟,小根堆)
数据结构·算法·leetcode
Morwit15 小时前
【力扣hot100】 312. 戳气球(区间dp)
c++·算法·leetcode
Q741_14716 小时前
C++ 栈 模拟 力扣 394. 字符串解码 每日一题 题解
c++·算法·leetcode·模拟·