Word Pattern
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
.
Example 1:
Example 2:
Example 3:
Example 4:
Notes:
You may assume pattern
contains only lowercase letters, and str
contains lowercase letters that may be separated by a single space.
分析
2个map,存的是当前Index,每次比较map值,也就是之前index。
注意get(key,defaultvalue)用法,defaultvalue要用-1 不能用0.
Last updated