LeetCode 2825. Make String a Subsequence Using Cyclic Increments
You are given two 0-indexed strings str1 and str2.
In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.
Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.
Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.
-----------------------------------------
給定兩個 0 索引的字符串 str1 和 str2。
在操作中,您在 str1 中選擇一組索引,并且對于該組中的每個索引 i,將 str1[i] 循環(huán)遞增到下一個字符。 即“a”變?yōu)椤癰”,“b”變?yōu)椤癱”,依此類推,“z”變?yōu)椤癮”。
如果最多執(zhí)行一次操作可以使 str2 成為 str1 的子序列,則返回 true,否則返回 false。
注意:字符串的子序列是通過刪除一些(可能沒有)字符而不影響剩余字符的相對位置而從原始字符串形成的新字符串。
利用雙指針做法即可;最后判斷str2的指針是否等于字符串的長度;
Runtime:?7 ms, faster than?100.00%?of?Java?online submissions for?Make String a Subsequence Using Cyclic Increments.
Memory Usage:?44.5 MB, less than?100.00%?of?Java?online submissions for?Make String a Subsequence Using Cyclic Increments.