[LeetCode] Word Pattern II - jcliBlogger - 博客园
[LeetCode] Word Pattern II
Problem Description:
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 substring in str
.
Examples:
- pattern =
"abab"
, str ="redblueredblue"
should return true. - pattern =
"aaaa"
, str ="asdasdasdasd"
should return true. - pattern =
"aabb"
, str ="xyzabcxzyabc"
should return false.
- pattern =
Notes:
You may assume both pattern
and str
contains only lowercase letters.
The problem becomes much more difficult after the spaces are removed. Now we need to determine which part matchs which part by ourselves. This post shares a very clear solution in Java, which is rewritten below in C++.
Read full article from [LeetCode] Word Pattern II - jcliBlogger - 博客园
No comments:
Post a Comment