Day16-205. Isomorphic Strings

今日题目:205. Isomorphic Strings(Easy)

Given two strings s and t, determine if they are isomorphic.

Two strings s and t are isomorphic if the characters in s can be replaced to get t.

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

Example 1:
Input: s = "egg", t = "add"
Output: true

解题技巧

My solution

class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        s = list(s)
        t = list(t)
        
        temp = {}
        if len(s) != len(t):
            return False
        
        for i in range(len(s)):
            if s[i] in temp:
                if temp[s[i]]!=t[i]:
                    return False
            
            else:#not in temp
                #不在里面但是内容已经有被建过了
                if t[i] in temp.values():
                    return False
                    
                else:
                    temp[s[i]]=t[i]
                
                
        return True

Result

https://ithelp.ithome.com.tw/upload/images/20211001/20140843Q5BPz5pMsY.png

其他内容待补 等我等我
拜托拜托


<<:  DAY16 - 档案处理 - 上传前预览

>>:  DAY16-前後端合体 建立打卡页面-前端元件篇

[鼠年全马] W34 - Vue出一个旅馆预约平台(8)

这周要来将 [预约页面] 最後的 房间详细资讯 完成!! [标题] (已完成) [预约功能] (已完...

离职倒数6天:把事业分解成几个必然的选择题,是成功学的陷阱

今天跟朋友在讨论《过度努力》时,朋友说自己对「冒牌者效应」这个词的感觉很复杂 他觉得自己的确有这个词...

Day 16:自动补全!coc.nvim

一个好的自动补全工具可以让你工作效率翻倍,你不用再去查文件了,自动补全不仅可以告诉你这里有什麽函数可...

Day20-自制下拉式选单_我就想要美美的

今天来弄一个自制的漂亮下拉式选单 首先下拉式选单,会有上面可以按的地方跟下方会弹出来的悬浮按钮 我这...