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

相关推荐
尋有緣10 小时前
力扣1327-列出指定时间段内所有的下单产品
leetcode·oracle·数据库开发
FMRbpm11 小时前
栈练习--------从链表中移除节点(LeetCode 2487)
数据结构·c++·leetcode·链表·新手入门
程序员-King.11 小时前
day109—同向双指针(字符串)—每个字符最多出现两次的最长子字符串(LeetCode-3090)
算法·leetcode·双指针
青山的青衫11 小时前
【单调栈和单调队列】LeetCode hot100+面试高频
算法·leetcode·面试
狗头实习生11 小时前
电话号码字母组合
java·算法·leetcode
sin_hielo12 小时前
leetcode 3432
数据结构·算法·leetcode
尋有緣12 小时前
力扣1083-销售分析II
leetcode·oracle·数据库开发
尋有緣13 小时前
力扣574-当选者
leetcode·oracle·数据库开发
程序员-King.13 小时前
day110—同向双指针(数组)—最多K个重复元素的最长子数组(LeetCode-2958)
算法·leetcode·双指针