My current approach..python three lines using sets

  • 0
    class Solution(object):
        def wordPattern(self, pattern, str):
            :type pattern: str
            :type str: str
            :rtype: bool
            return len(set(pattern)) == len(set(zip(pattern, str.split()))) and len(set(pattern)) == len(set(str.split())) and len(pattern) == len(str.split())

  • 0

    You can definitely do this:
    len(set(zip(list(pattern), str.split()))) == len(set(pattern)) == len(set(str.split()))

Log in to reply

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