首页 > 其他 > 详细

leetcode——290.单词规律/205.同构字符串

时间:2019-10-17 10:06:06      阅读:60      评论:0      收藏:0      [点我收藏+]

简单题。同样的做法。

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

 

leetcode——290.单词规律/205.同构字符串

原文:https://www.cnblogs.com/taoyuxin/p/11688738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!