-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathword-pattern.md
30 lines (20 loc) · 1.24 KB
/
word-pattern.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<p>Given a <code>pattern</code> and a string <code>str</code>, find if <code>str</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>str</code>.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> pattern = <code>"abba"</code>, str = <code>"dog cat cat dog"</code>
<strong>Output:</strong> true</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong>pattern = <code>"abba"</code>, str = <code>"dog cat cat fish"</code>
<strong>Output:</strong> false</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> pattern = <code>"aaaa"</code>, str = <code>"dog cat cat dog"</code>
<strong>Output:</strong> false</pre>
<p><strong>Example 4:</strong></p>
<pre>
<strong>Input:</strong> pattern = <code>"abba"</code>, str = <code>"dog dog dog dog"</code>
<strong>Output:</strong> false</pre>
<p><b>Notes:</b><br />
You may assume <code>pattern</code> contains only lowercase letters, and <code>str</code> contains lowercase letters that may be separated by a single space.</p>