java.lang.Object
g1801_1900.s1844_replace_all_digits_with_characters.Solution

public class Solution extends Object
1844 - Replace All Digits with Characters.<p>Easy</p> <p>You are given a <strong>0-indexed</strong> string <code>s</code> that has lowercase English letters in its <strong>even</strong> indices and digits in its <strong>odd</strong> indices.</p> <p>There is a function <code>shift(c, x)</code>, where <code>c</code> is a character and <code>x</code> is a digit, that returns the <code>x<sup>th</sup></code> character after <code>c</code>.</p> <ul> <li>For example, <code>shift('a', 5) = 'f'</code> and <code>shift('x', 0) = 'x'</code>.</li> </ul> <p>For every <strong>odd</strong> index <code>i</code>, you want to replace the digit <code>s[i]</code> with <code>shift(s[i-1], s[i])</code>.</p> <p>Return <code>s</code> <em>after replacing all digits. It is <strong>guaranteed</strong> that</em> <code>shift(s[i-1], s[i])</code> <em>will never exceed</em> <code>'z'</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;a1c1e1&rdquo;</p> <p><strong>Output:</strong> &ldquo;abcdef&rdquo;</p> <p><strong>Explanation:</strong> The digits are replaced as follows:</p> <ul> <li> <p>s[1] -> shift(&lsquo;a&rsquo;,1) = &lsquo;b&rsquo;</p> </li> <li> <p>s[3] -> shift(&lsquo;c&rsquo;,1) = &lsquo;d&rsquo;</p> </li> <li> <p>s[5] -> shift(&lsquo;e&rsquo;,1) = &lsquo;f&rsquo;</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;a1b2c3d4e&rdquo;</p> <p><strong>Output:</strong> &ldquo;abbdcfdhe&rdquo;</p> <p><strong>Explanation:</strong> The digits are replaced as follows:</p> <ul> <li> <p>s[1] -> shift(&lsquo;a&rsquo;,1) = &lsquo;b&rsquo;</p> </li> <li> <p>s[3] -> shift(&lsquo;b&rsquo;,2) = &lsquo;d&rsquo;</p> </li> <li> <p>s[5] -> shift(&lsquo;c&rsquo;,3) = &lsquo;f&rsquo;</p> </li> <li> <p>s[7] -> shift(&lsquo;d&rsquo;,4) = &lsquo;h&rsquo;</p> </li> </ul> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s</code> consists only of lowercase English letters and digits.</li> <li><code>shift(s[i-1], s[i]) <= 'z'</code> for all <strong>odd</strong> indices <code>i</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details