Class Solution
-
- All Implemented Interfaces:
public final class Solution3614 - Process String with Special Operations II.
Hard
You are given a string
sconsisting of lowercase English letters and the special characters:'*','#', and'%'.You are also given an integer
k.Build a new string
resultby processingsaccording to the following rules from left to right:If the letter is a lowercase English letter append it to
result.A
'*'removes the last character fromresult, if it exists.A
'#'duplicates the currentresultand appends it to itself.A
'%'reverses the currentresult.
Return the <code>k<sup>th</sup></code> character of the final string
result. Ifkis out of the bounds ofresult, return'.'.Example 1:
Input: s = "a#b%\*", k = 1
Output: "a"
Explanation:
The final
resultis"ba". The character at indexk = 1is'a'.Example 2:
Input: s = "cd%#\*#", k = 3
Output: "d"
Explanation:
The final
resultis"dcddcd". The character at indexk = 3is'd'.Example 3:
Input: s = "z\*#", k = 0
Output: "."
Explanation:
The final
resultis"". Since indexk = 0is out of bounds, the output is'.'.Constraints:
<code>1 <= s.length <= 10<sup>5</sup></code>
sconsists of only lowercase English letters and special characters'*','#', and'%'.<code>0 <= k <= 10<sup>15</sup></code>
The length of
resultafter processingswill not exceed <code>10<sup>15</sup></code>.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final CharacterprocessStr(String s, Long k)-
-
Method Detail
-
processStr
final Character processStr(String s, Long k)
-
-
-
-