Class Solution

java.lang.Object
g2301_2400.s2325_decode_the_message.Solution

public class Solution extends Object
2325 - Decode the Message.<p>Easy</p> <p>You are given the strings <code>key</code> and <code>message</code>, which represent a cipher key and a secret message, respectively. The steps to decode <code>message</code> are as follows:</p> <ol> <li>Use the <strong>first</strong> appearance of all 26 lowercase English letters in <code>key</code> as the <strong>order</strong> of the substitution table.</li> <li>Align the substitution table with the regular English alphabet.</li> <li>Each letter in <code>message</code> is then <strong>substituted</strong> using the table.</li> <li>Spaces <code>' '</code> are transformed to themselves.</li> </ol> <ul> <li>For example, given <code>key = &ldquo;<ins> <strong>hap</strong> </ins>p<ins> <strong>y</strong> </ins> <ins> <strong>bo</strong> </ins>y&rdquo;</code> (actual key would have <strong>at least one</strong> instance of each letter in the alphabet), we have the partial substitution table of (<code>'h' -> 'a'</code>, <code>'a' -> 'b'</code>, <code>'p' -> 'c'</code>, <code>'y' -> 'd'</code>, <code>'b' -> 'e'</code>, <code>'o' -> 'f'</code>).</li> </ul> <p>Return <em>the decoded message</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/05/08/ex1new4.jpg" alt="" /></p> <p><strong>Input:</strong> key = &ldquo;the quick brown fox jumps over the lazy dog&rdquo;, message = &ldquo;vkbs bs t suepuv&rdquo;</p> <p><strong>Output:</strong> &ldquo;this is a secret&rdquo;</p> <p><strong>Explanation:</strong> The diagram above shows the substitution table.</p> <p>It is obtained by taking the first appearance of each letter in &ldquo;<ins> <strong>the</strong> </ins> <ins> <strong>quick</strong> </ins> <ins> <strong>brown</strong> </ins> <ins> <strong>f</strong> </ins>o<ins> <strong>x</strong> </ins> <ins> <strong>j</strong> </ins>u<ins> <strong>mps</strong> </ins> o<ins> <strong>v</strong> </ins>er the <ins> <strong>lazy</strong> </ins> <ins> <strong>d</strong> </ins>o<ins> <strong>g</strong> </ins>&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/05/08/ex2new.jpg" alt="" /></p> <p><strong>Input:</strong> key = &ldquo;eljuxhpwnyrdgtqkviszcfmabo&rdquo;, message = &ldquo;zwx hnfx lqantp mnoeius ycgk vcnjrdb&rdquo;</p> <p><strong>Output:</strong> &ldquo;the five boxing wizards jump quickly&rdquo;</p> <p><strong>Explanation:</strong> The diagram above shows the substitution table.</p> <p>It is obtained by taking the first appearance of each letter in &ldquo;<ins> <strong>eljuxhpwnyrdgtqkviszcfmabo</strong> </ins>&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>26 <= key.length <= 2000</code></li> <li><code>key</code> consists of lowercase English letters and <code>' '</code>.</li> <li><code>key</code> contains every letter in the English alphabet (<code>'a'</code> to <code>'z'</code>) <strong>at least once</strong>.</li> <li><code>1 <= message.length <= 2000</code></li> <li><code>message</code> consists of lowercase English letters and <code>' '</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details