Given a pattern and a list of words, check whether the words match the pattern.
Sample Input:
pattern = “ABBA”
words = “hello kitty kitty hello”
Sample Output:
True
In the above input sample, pattern “ABBA” means there should be two words, A and B, and the order should be 1A – 2B – 3B – 4A. The sample words match the pattern, so the output is True.
数据结构和算法:初级练习题# 4 – 匹配单词模式
给定一个字符模式和一组单词,检查该组单词是否和字符模式匹配。
输入样例:
pattern = “ABBA”
words = “hello kitty kitty hello”
输出样例:
True
在上面的输入样例中,字符模式”ABBA“表示有两个不同单词A和B,排列顺序是 1A-2B-3B-4A。样例单词组符合这个模式,所以输出结果是 True。