Decoded String at Index

Decoded String at Index

An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:
If the character read is a letter, that letter is written onto the tape.
If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total.
Now for some encoded string S, and an index K, find and return the K-th letter (1 indexed) in the decoded string. —— [ 题目描述 ]

  • Markdown和扩展Markdown简洁的语法

解法

每个位置对应着最终解密的字符中的位置,如果K大于当前位置,说明K%size后的位置也是K的位置,因为当前位置经过重复后会大于K

猜你喜欢

转载自blog.csdn.net/vincenture/article/details/81461457
今日推荐