Skip to content

Commit c0fa3e5

Browse files
authored
Added solution for 1876
1 parent ac41abc commit c0fa3e5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
impl Solution {
2+
// Loop through string and create substrings of size 3 along the way. Compare and make sure each character in substring is unique. If it is add 1 to the result
3+
pub fn count_good_substrings(s: String) -> i32 {
4+
let len = s.len();
5+
let mut substrings = 0;
6+
7+
if len > 2 {
8+
for c in 0..(len - 2) {
9+
let first_char = s.chars().nth(c).unwrap();
10+
let second_char = s.chars().nth(c + 1).unwrap();
11+
let third_char = s.chars().nth(c + 2).unwrap();
12+
13+
if (first_char != second_char) && (second_char != third_char) && (third_char != first_char) {
14+
substrings += 1;
15+
}
16+
}
17+
}
18+
19+
return substrings;
20+
}
21+
}

0 commit comments

Comments
 (0)