[copy title]:
Given a pattern
and a string str
, find if str
follows the same pattern.
Here follow means a full match, such that there is a bijection between a letter in pattern
and a non-empty word in str
.
Examples:
- pattern =
"abba"
, str ="dog cat cat dog"
should return true. - pattern =
"abba"
, str ="dog cat cat fish"
should return false. - pattern =
"aaaa"
, str ="dog cat cat dog"
should return false. - pattern =
"abba"
, str ="dog dog dog dog"
should return false.
Notes:
You may assume pattern
contains only lowercase letters, and str
contains lowercase letters separated by a single space.
[brute force solution]:
Time analysis:
Space Analysis:
[Optimized]:
Time analysis:
Space Analysis:
[Wonderful output conditions]:
[Wonderful corner case]:
[Thinking question]:
[One sentence idea]:
[Input amount]: Empty: Normal situation: Extra large: Extra small: Special situations handled in the program: Abnormal situations (Illegal and unreasonable input):
[Paint]:
[One brush]:
[Second brush]:
[Three brushes]:
[Four brushes]:
[Five brushes]:
[Results of five-minute naked eye debug]:
[Summarize]:
[Complexity]: Time complexity: O( ) Space complexity: O( )
[English data structures or algorithms, why not use other data structures or algorithms]:
[Key templating code]:
[Other solutions]:
[Follow Up]:
[The topics given by LC change and change]:
291. Word Pattern II has no spaces, backtracking?
[Code style]: