Word Pattern II
Given apattern
and a stringstr
, find ifstr
follows the same pattern.
Here follow means a full match, such that there is a bijection between a letter inpattern
and anon-empty substring instr
.
Examples: (Note: In this problem the words in string are not separated by spaces, like the previous problem)
pattern =
"abab"
, str ="redblueredblue"
should return true.
pattern =
"aaaa"
, str ="asdasdasdasd"
should return true.
pattern =
"aabb"
, str ="xyzabcxzyabc"
should return false.
Notes:
You may assume bothpattern
andstr
contains only lowercase letters.
Last updated
Was this helpful?