首页 > 其他 > 详细

[LeetCode] Word Pattern 词语模式

时间:2015-10-06 14:08:06      阅读:257      评论:0      收藏:0      [点我收藏+]

 

Given a pattern and a string str, find if str follows the same pattern.

Examples:

  1. pattern = "abba", str = "dog cat cat dog" should return true.
  2. pattern = "abba", str = "dog cat cat fish" should return false.
  3. pattern = "aaaa", str = "dog cat cat dog" should return false.
  4. pattern = "abba", str = "dog dog dog dog" should return false.

Notes:

  1. Both pattern and str contains only lowercase alphabetical letters.
  2. Both pattern and str do not have leading or trailing spaces.
  3. Each word in str is separated by a single space.
  4. Each letter in pattern must map to a word with length that is at least 1.

Credits:
Special thanks to @minglotus6 for adding this problem and creating all test cases.

 

[LeetCode] Word Pattern 词语模式

原文:http://www.cnblogs.com/grandyang/p/4857022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!