Skip to content

Commit 1dd28cb

Browse files
authored
feat: add solutions to lc problem: No.0721 (doocs#3273)
No.0721.Accounts Merge
1 parent 6966d28 commit 1dd28cb

File tree

12 files changed

+952
-360
lines changed

12 files changed

+952
-360
lines changed

solution/0000-0099/0091.Decode Ways/README_EN.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,66 @@ tags:
1717

1818
<!-- description:start -->
1919

20-
<p>A message containing letters from <code>A-Z</code> can be <strong>encoded</strong> into numbers using the following mapping:</p>
20+
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p>
2121

22-
<pre>
23-
&#39;A&#39; -&gt; &quot;1&quot;
24-
&#39;B&#39; -&gt; &quot;2&quot;
25-
...
26-
&#39;Z&#39; -&gt; &quot;26&quot;
27-
</pre>
22+
<p><code>&quot;1&quot; -&gt; &#39;A&#39;<br />
23+
&quot;2&quot; -&gt; &#39;B&#39;<br />
24+
...<br />
25+
&quot;25&quot; -&gt; &#39;Y&#39;<br />
26+
&quot;26&quot; -&gt; &#39;Z&#39;</code></p>
2827

29-
<p>To <strong>decode</strong> an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, <code>&quot;11106&quot;</code> can be mapped into:</p>
28+
<p>However, while decoding the message, you realize that there are many different ways you can decode the message because some codes are contained in other codes (<code>&quot;2&quot;</code> and <code>&quot;5&quot;</code> vs <code>&quot;25&quot;</code>).</p>
29+
30+
<p>For example, <code>&quot;11106&quot;</code> can be decoded into:</p>
3031

3132
<ul>
32-
<li><code>&quot;AAJF&quot;</code> with the grouping <code>(1 1 10 6)</code></li>
33-
<li><code>&quot;KJF&quot;</code> with the grouping <code>(11 10 6)</code></li>
33+
<li><code>&quot;AAJF&quot;</code> with the grouping <code>(1, 1, 10, 6)</code></li>
34+
<li><code>&quot;KJF&quot;</code> with the grouping <code>(11, 10, 6)</code></li>
35+
<li>The grouping <code>(1, 11, 06)</code> is invalid because <code>&quot;06&quot;</code> is not a valid code (only <code>&quot;6&quot;</code> is valid).</li>
3436
</ul>
3537

36-
<p>Note that the grouping <code>(1 11 06)</code> is invalid because <code>&quot;06&quot;</code> cannot be mapped into <code>&#39;F&#39;</code> since <code>&quot;6&quot;</code> is different from <code>&quot;06&quot;</code>.</p>
37-
38-
<p>Given a string <code>s</code> containing only digits, return <em>the <strong>number</strong> of ways to <strong>decode</strong> it</em>.</p>
38+
<p>Note: there may be strings that are impossible to decode.<br />
39+
<br />
40+
Given a string s containing only digits, return the <strong>number of ways</strong> to <strong>decode</strong> it. If the entire string cannot be decoded in any valid way, return <code>0</code>.</p>
3941

4042
<p>The test cases are generated so that the answer fits in a <strong>32-bit</strong> integer.</p>
4143

4244
<p>&nbsp;</p>
4345
<p><strong class="example">Example 1:</strong></p>
4446

45-
<pre>
46-
<strong>Input:</strong> s = &quot;12&quot;
47-
<strong>Output:</strong> 2
48-
<strong>Explanation:</strong> &quot;12&quot; could be decoded as &quot;AB&quot; (1 2) or &quot;L&quot; (12).
49-
</pre>
47+
<div class="example-block">
48+
<p><strong>Input:</strong> <span class="example-io">s = &quot;12&quot;</span></p>
49+
50+
<p><strong>Output:</strong> <span class="example-io">2</span></p>
51+
52+
<p><strong>Explanation:</strong></p>
53+
54+
<p>&quot;12&quot; could be decoded as &quot;AB&quot; (1 2) or &quot;L&quot; (12).</p>
55+
</div>
5056

5157
<p><strong class="example">Example 2:</strong></p>
5258

53-
<pre>
54-
<strong>Input:</strong> s = &quot;226&quot;
55-
<strong>Output:</strong> 3
56-
<strong>Explanation:</strong> &quot;226&quot; could be decoded as &quot;BZ&quot; (2 26), &quot;VF&quot; (22 6), or &quot;BBF&quot; (2 2 6).
57-
</pre>
59+
<div class="example-block">
60+
<p><strong>Input:</strong> <span class="example-io">s = &quot;226&quot;</span></p>
61+
62+
<p><strong>Output:</strong> <span class="example-io">3</span></p>
63+
64+
<p><strong>Explanation:</strong></p>
65+
66+
<p>&quot;226&quot; could be decoded as &quot;BZ&quot; (2 26), &quot;VF&quot; (22 6), or &quot;BBF&quot; (2 2 6).</p>
67+
</div>
5868

5969
<p><strong class="example">Example 3:</strong></p>
6070

61-
<pre>
62-
<strong>Input:</strong> s = &quot;06&quot;
63-
<strong>Output:</strong> 0
64-
<strong>Explanation:</strong> &quot;06&quot; cannot be mapped to &quot;F&quot; because of the leading zero (&quot;6&quot; is different from &quot;06&quot;).
65-
</pre>
71+
<div class="example-block">
72+
<p><strong>Input:</strong> <span class="example-io">s = &quot;06&quot;</span></p>
73+
74+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
75+
76+
<p><strong>Explanation:</strong></p>
77+
78+
<p>&quot;06&quot; cannot be mapped to &quot;F&quot; because of the leading zero (&quot;6&quot; is different from &quot;06&quot;). In this case, the string is not a valid encoding, so return 0.</p>
79+
</div>
6680

6781
<p>&nbsp;</p>
6882
<p><strong>Constraints:</strong></p>

0 commit comments

Comments
 (0)