zoukankan      html  css  js  c++  java
  • 边工作边刷题:70天一遍leetcode: day 31

    Isomorphic Strings

    要点:一道简单题,要点就是map不是bijection的,所以要用两个map来表示bijection

    class Solution(object):
        def isIsomorphic(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            smap = {}
            tmap = {}
            if len(s)!=len(t): return False
            for i in range(len(s)):
                if s[i] not in smap:
                    smap[s[i]]=t[i]
                elif smap[s[i]]!=t[i]:
                    return False
                
                if t[i] not in tmap:
                    tmap[t[i]]=s[i]
                elif tmap[t[i]]!=s[i]:
                    return False
            
            return True
            
    
  • 相关阅读:
    0722
    SGU
    预测一下吧
    0625
    0624
    0610
    0607
    0604
    poj2455Secret Milking Machine【二分 + 最大流】
    BZOJ3489: A simple rmq problem
  • 原文地址:https://www.cnblogs.com/absolute/p/5678121.html
Copyright © 2011-2022 走看看