# LeetCode 2825. Make String a Subsequence Using Cyclic Increments https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/description/ ## 題目大意 允許一次以循環偏移的方式調整 `str1` 的每個字元,能否使 `str2` 的內容為其子序列 字元以這種方式偏移的話 `'a'` 會變成 `'b'` 而 `'z'` 會變成 `'a'` ## 思考 每個都試試看,本來就會是子序列 or 偏移後能是子序列 C++ 參考解答: ```cpp! class Solution { public: bool canMakeSubsequence(string str1, string str2) { auto it = str2.begin(), end = str2.end(); for (const char &c : str1) { if (c == *it || (((c - 'a' + 1) % 26) + 'a') == *it) { if (++it == end) return true; } } return false; } }; ``` Go 參考解答: ```go! func canMakeSubsequence(str1 string, str2 string) bool { j := 0 n := len(str2) for i := 0; i < len(str1); i++ { if j == n { return true } c1, c2 := uint8(str1[i]), uint8(str2[j]) if c1 == c2 || ((c1-'a'+1)%26+'a') == c2 { j++ } } return j == n } ```