Word Pattern
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 a non-empty word instr
.
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 assumepattern
contains only lowercase letters, andstr
contains lowercase letters separated by a single space.
Last updated
Was this helpful?