leetcode?python 290. Word Pattern

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode?python 290. Word Pattern相关的知识,希望对你有一定的参考价值。

class Solution(object):
    def wordPattern(self, pattern, str):
        """
        :type pattern: str
        :type str: str
        :rtype: bool
        """
        tag=0
        tagdic={}
        tagList=[]
        i=0
        while i<len(pattern):
            if tagdic.has_key(pattern[i]):
                tagList.append(tagdic.get(pattern[i]))
            else:
                tagdic.setdefault(pattern[i],tag)
                tagList.append(tag)
                tag+=1
            i+=1
        strList=str.split(‘ ‘)
   
        tagdic={};tag=0;tagList2=[];i=0
   
        while i<len(strList):
         
            if tagdic.has_key(strList[i]):
                tagList2.append(tagdic.get(strList[i]))
            else:
                tagdic.setdefault(strList[i],tag)
                tagList2.append(tag)
                tag+=1
            i+=1
        
        return tagList==tagList2






























以上是关于leetcode?python 290. Word Pattern的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode290]Word Pattern

Leetcode 290. Word Pattern

LeetCode_290. Word Pattern

[leetcode]290.Word Pattern

leetcode290. Word Pattern

LeetCode 290. Word Pattern