简单题。同样的做法。
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.单词规律的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did170491