|
| 1 | +<p>A string can be <strong>abbreviated</strong> by replacing any number of <strong>non-adjacent</strong>, <strong>non-empty</strong> substrings with their lengths. The lengths <strong>should not</strong> have leading zeros.</p> |
| 2 | + |
| 3 | +<p>For example, a string such as <code>"substitution"</code> could be abbreviated as (but not limited to):</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li><code>"s10n"</code> (<code>"s <u>ubstitutio</u> n"</code>)</li> |
| 7 | + <li><code>"sub4u4"</code> (<code>"sub <u>stit</u> u <u>tion</u>"</code>)</li> |
| 8 | + <li><code>"12"</code> (<code>"<u>substitution</u>"</code>)</li> |
| 9 | + <li><code>"su3i1u2on"</code> (<code>"su <u>bst</u> i <u>t</u> u <u>ti</u> on"</code>)</li> |
| 10 | + <li><code>"substitution"</code> (no substrings replaced)</li> |
| 11 | +</ul> |
| 12 | + |
| 13 | +<p>The following are <strong>not valid</strong> abbreviations:</p> |
| 14 | + |
| 15 | +<ul> |
| 16 | + <li><code>"s55n"</code> (<code>"s <u>ubsti</u> <u>tutio</u> n"</code>, the replaced substrings are adjacent)</li> |
| 17 | + <li><code>"s010n"</code> (has leading zeros)</li> |
| 18 | + <li><code>"s0ubstitution"</code> (replaces an empty substring)</li> |
| 19 | +</ul> |
| 20 | + |
| 21 | +<p>Given a string <code>word</code> and an abbreviation <code>abbr</code>, return <em>whether the string <strong>matches</strong> the given abbreviation</em>.</p> |
| 22 | + |
| 23 | +<p>A <strong>substring</strong> is a contiguous <strong>non-empty</strong> sequence of characters within a string.</p> |
| 24 | + |
| 25 | +<p> </p> |
| 26 | +<p><strong class="example">Example 1:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input:</strong> word = "internationalization", abbr = "i12iz4n" |
| 30 | +<strong>Output:</strong> true |
| 31 | +<strong>Explanation:</strong> The word "internationalization" can be abbreviated as "i12iz4n" ("i <u>nternational</u> iz <u>atio</u> n"). |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p><strong class="example">Example 2:</strong></p> |
| 35 | + |
| 36 | +<pre> |
| 37 | +<strong>Input:</strong> word = "apple", abbr = "a2e" |
| 38 | +<strong>Output:</strong> false |
| 39 | +<strong>Explanation:</strong> The word "apple" cannot be abbreviated as "a2e". |
| 40 | +</pre> |
| 41 | + |
| 42 | +<p> </p> |
| 43 | +<p><strong>Constraints:</strong></p> |
| 44 | + |
| 45 | +<ul> |
| 46 | + <li><code>1 <= word.length <= 20</code></li> |
| 47 | + <li><code>word</code> consists of only lowercase English letters.</li> |
| 48 | + <li><code>1 <= abbr.length <= 10</code></li> |
| 49 | + <li><code>abbr</code> consists of lowercase English letters and digits.</li> |
| 50 | + <li>All the integers in <code>abbr</code> will fit in a 32-bit integer.</li> |
| 51 | +</ul> |
0 commit comments