java.lang.Object
g0801_0900.s0880_decoded_string_at_index.Solution

public class Solution extends Object
880 - Decoded String at Index.<p>Medium</p> <p>You are given an encoded string <code>s</code>. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:</p> <ul> <li>If the character read is a letter, that letter is written onto the tape.</li> <li>If the character read is a digit <code>d</code>, the entire current tape is repeatedly written <code>d - 1</code> more times in total.</li> </ul> <p>Given an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>letter ( <strong>1-indexed)</strong> in the decoded string</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;leet2code3&rdquo;, k = 10</p> <p><strong>Output:</strong> &ldquo;o&rdquo;</p> <p><strong>Explanation:</strong> The decoded string is &ldquo;leetleetcodeleetleetcodeleetleetcode&rdquo;. The 10<sup>th</sup> letter in the string is &ldquo;o&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;ha22&rdquo;, k = 5</p> <p><strong>Output:</strong> &ldquo;h&rdquo;</p> <p><strong>Explanation:</strong> The decoded string is &ldquo;hahahaha&rdquo;. The 5<sup>th</sup> letter is &ldquo;h&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;a2345678999999999999999&rdquo;, k = 1</p> <p><strong>Output:</strong> &ldquo;a&rdquo;</p> <p><strong>Explanation:</strong> The decoded string is &ldquo;a&rdquo; repeated 8301530446056247680 times. The 1<sup>st</sup> letter is &ldquo;a&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= s.length <= 100</code></li> <li><code>s</code> consists of lowercase English letters and digits <code>2</code> through <code>9</code>.</li> <li><code>s</code> starts with a letter.</li> <li><code>1 <= k <= 10<sup>9</sup></code></li> <li>It is guaranteed that <code>k</code> is less than or equal to the length of the decoded string.</li> <li>The decoded string is guaranteed to have less than <code>2<sup>63</sup></code> letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • decodeAtIndex

      public String decodeAtIndex(String s, int k)