@@ -0,0 +1,734 @@
+class Solution:%0A    def wordPattern(self, pattern: str, s: str) -%3E bool:%0A        # check pattern length matches sentence length:%0A        s_words = s.split()%0A        if len(s_words) != len(pattern):%0A            return False%0A        %0A        # check every letter in the pattern is mapped to the same word each time:%0A        pattern_map = %7B%7D%0A        for i in range(len(pattern)):%0A            c = pattern%5Bi%5D%0A            word = s_words%5Bi%5D%0A            if c in pattern_map:%0A                if pattern_map%5Bc%5D != word:%0A                    return False%0A            else:%0A                pattern_map%5Bc%5D = word%0A        %0A        # check there aren't 2 pattern letters mapped to the same word:%0A        return len(set(pattern)) == len(set(s_words))%0A

290. Word Pattern