Untitled
unknown
plain_text
10 months ago
623 B
3
Indexable
public class Solution {
public int countGoodSubstrings(String s) {
int n = s.length();
if (n < 3) return 0;
int count = 0;
int i = 0, j = 2; // Fixed-size window of 3
while (j < n) {
// Check if the current substring has unique characters
char a = s.charAt(i);
char b = s.charAt(i + 1);
char c = s.charAt(j);
if (a != b && b != c && a != c) {
count++;
}
// Slide the window
i++;
j++;
}
return count;
}
}
Editor is loading...
Leave a Comment