File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ """
3+ @param pattern: a string, denote pattern string
4+ @param teststr: a string, denote matching string
5+ @return: an boolean, denote whether the pattern string and the matching string match or not
6+ """
7+ def wordPattern (self , pattern , teststr ):
8+ # write your code here
9+ di = {}
10+ pattern_mapping = []
11+ _id = 0
12+ for c in pattern :
13+ if c not in di :
14+ di [c ] = _id
15+ _id += 1
16+ pattern_mapping .append (di [c ])
17+ _id = 0
18+ di .clear ()
19+ str_mapping = []
20+ words = teststr .split (' ' )
21+ for word in words :
22+ if word not in di :
23+ di [word ] = _id
24+ _id += 1
25+ str_mapping .append (di [word ])
26+ return str_mapping == pattern_mapping
27+
28+ # easy: https://www.lintcode.com/problem/word-pattern/
You can’t perform that action at this time.
0 commit comments