290. Word Pattern word matching pattern

[copy title]:

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.

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:
You may assume pattern contains only lowercase letters, and str contains lowercase letters separated by a single space.

 [brute force solution]:

Time analysis:

Space Analysis:

 [Optimized]:

Time analysis:

Space Analysis:

[Wonderful output conditions]:

[Wonderful corner case]:

[Thinking question]:

[One sentence idea]:

[Input amount]: Empty: Normal situation: Extra large: Extra small: Special situations handled in the program: Abnormal situations (Illegal and unreasonable input):

[Paint]:

[One brush]:

[Second brush]:

[Three brushes]:

[Four brushes]:

[Five brushes]:

  [Results of five-minute naked eye debug]:

[Summarize]:

[Complexity]: Time complexity: O( ) Space complexity: O( )

[English data structures or algorithms, why not use other data structures or algorithms]:

[Key templating code]:

[Other solutions]:

[Follow Up]:

[The topics given by LC change and change]:

291. Word Pattern II has no spaces, backtracking?

 [Code style]:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324771961&siteId=291194637
Recommended