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

相关推荐
longlongzihan4 小时前
LeetCode 17电话号码的字母组合:回溯算法(DFS)详解
c++·算法·leetcode·深度优先
smj2302_7968265210 小时前
解决leetcode第4064题至多一次取反能被k整除的最长子数组II
python·算法·leetcode
青山木10 小时前
Hot 100 --- 下一个排列
java·数据结构·算法·leetcode
垆边人似月.10 小时前
字符串重排后最大字典序
算法·leetcode·职场和发展
代码什么用11 小时前
LeetCode-42. 接雨水
算法·leetcode
yi01113 小时前
DAY17: LeetCode 139|单词拆分:从“把单词删掉”到用 DP 记录合法切口
人工智能·笔记·python·算法·leetcode·动态规划
Navigator_Z15 小时前
LeetCode //C - 1269. Number of Ways to Stay in the Same Place After Some Steps
c语言·算法·leetcode
垆边人似月.16 小时前
华为算法题:最长连续递增子序列的变
数据结构·算法·leetcode
longlongzihan17 小时前
LeetCode 56合并区间:排序与贪心
c++·算法·leetcode
kukubuzai17 小时前
二分查找系列一
数据结构·算法·leetcode