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

相关推荐
椰羊~王小美1 小时前
LeetCode -- Flora -- edit 2025-04-27
算法·leetcode·职场和发展
mit6.8246 小时前
[Lc_week] 447 | 155 | Q1 | hash | pair {}调用
算法·leetcode·哈希算法·散列表
vim怎么退出9 小时前
43.验证二叉搜索树
前端·leetcode
编程绿豆侠11 小时前
力扣HOT100之链表:23. 合并 K 个升序链表
算法·leetcode·链表
OpenC++15 小时前
【C++QT】Layout 布局管理控件详解
c++·经验分享·qt·leetcode
1白天的黑夜115 小时前
贪心算法-860.柠檬水找零-力扣(LeetCode)
c++·算法·leetcode·贪心算法
Y1nhl16 小时前
力扣hot100_子串_python版本
开发语言·python·算法·leetcode·职场和发展
共享家95271 天前
栈相关算法题解题思路与代码实现分享
c++·leetcode
Wendy_robot1 天前
【前缀和计算和+哈希表查找次数】Leetcode 560. 和为 K 的子数组
c++·算法·leetcode
o独酌o1 天前
算法习题-力扣446周赛题解
算法·leetcode