Flashcards
Word pattern
Cards in this deck (1)
- 1Input: pattern = "abba", str = "dog cat cat dog" Output: trueclass Solution:
def wordPattern(self, pattern: str, str: str) -> bool:
strSplit = str.split()
patSplit = [pattern[i:i+1] for i in range(0, len(pattern))]
if len(patSplit) != len(strSplit): return False
strDict = {}
for i,j in zip(strSplit,patSplit):
if i in strDict:
if strDict[i] != j:
return False
elif j in strDict.values():
return False
else:
strDict[i] = j
return True
Information
- Description
- Flashcards on Word pattern, created by Suhas S on 14/09/2019.
- Created by
- Suhas S
- Views
- 0
- Rating