12/03/2024
[LeetCode] 2825. Make String a Subsequence Using Cyclic Increments
Problem : https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/
There are 2 important rules:
class Solution {
public boolean canMakeSubsequence(String str1, String str2) {
int M = str1.length(), N = str2.length();
int i = 0, j = 0;
while (i < M && j < N) {
int a = str1.charAt(i) - 'a', b = str2.charAt(j) - 'a';
if (a == b || (a + 1) % 26 == b) {
i += 1;
j += 1;
} else {
i += 1;
}
}
// Check if all characters of str2 have been matched
return j == N;
}
}
Subscribe to:
Posts (Atom)