4 line python


  • 0

    class Solution(object):

    def wordPattern(self, pattern, str):
        words = str.split()
        if len(words) != len(pattern):
            return False
        zip_pattern_words = [words[i] + pattern[i] for i in xrange(len(words))]
        return len(set(pattern)) == len(set(words)) == len(set(zip_pattern_words))

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.