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

相关推荐
im_AMBER12 分钟前
Leetcode 145 回文数 | 加一
数据结构·算法·leetcode
Tisfy26 分钟前
LeetCode 2906.构造乘积矩阵:前后缀分解
算法·leetcode·前缀和·矩阵·题解·前后缀分解
旖-旎1 小时前
前缀和(和为K的子数组)(5)
c++·算法·leetcode·前缀和·哈希算法·散列表
凌波粒1 小时前
LeetCode--203.移除链表元素(链表)
java·算法·leetcode·链表
Q741_1471 小时前
力扣经典模板题 前缀积 力扣 2906. 构造乘积矩阵 每日一题 哈希表 找规律 力扣 13. 罗马数字转整数 C++
算法·leetcode·前缀和·矩阵
北顾笙9801 小时前
day05-数据结构力扣
数据结构·leetcode·哈希算法
1104.北光c°2 小时前
Leetcode206.反转链表 迭代+递归 【hot100算法个人笔记】【java写法】
java·数据结构·笔记·算法·leetcode·链表·反转链表
圣保罗的大教堂2 小时前
leetcode 2906. 构造乘积矩阵 中等
leetcode
做怪小疯子2 小时前
Leetcode刷题——矩阵遍历
算法·leetcode·矩阵
羊小猪~~2 小时前
算法/力扣--链表经典题目
数据结构·后端·考研·算法·leetcode·链表·面试