加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

leetcode——290.单词规律

发布时间:2020-12-20 10:17:14 所属栏目:Python 来源:网络整理
导读:简单题。同样的做法。 290. class Solution: def wordPattern(self,pattern: str,str: str) - bool: p = {} q =str.split( ‘ ‘ ) if len(pattern)!= len(q): return False for i in range(len(pattern)): if pattern[i] in p: if p[pattern[i]]!= q[i]: re

简单题。同样的做法。

290.

class Solution:
    def wordPattern(self,pattern: str,str: str) -> bool:
        p={}
        q=str.split( )
        if len(pattern)!=len(q):
            return False
        for i in range(len(pattern)):
            if pattern[i] in p:
                if p[pattern[i]]!=q[i]:
                    return False
            else:
                if q[i] not in q[:i]:
                    p[pattern[i]]=q[i]
                else:
                    return False
        return True
执行用时 :32 ms,在所有?python3?提交中击败了99.52%的用户
内存消耗 :13.9 MB,在所有?python3?提交中击败了5.58%的用户
?
205.
class Solution:
    def isIsomorphic(self,s: str,t: str) -> bool:
        p={}
        for i in range(len(s)):
            if s[i] in p:
                if p[s[i]]!=t[i]:
                    return False
            else:
                if t[i] not in t[:i]:
                    p[s[i]]=t[i]
                else:
                    return False
        return True
执行用时 :44 ms,在所有?python3?提交中击败了98.06%的用户
内存消耗 :14.1 MB,在所有?python3?提交中击败了5.63%的用户
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?——2019.10.16

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读