Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c958349

Browse files
Substrings of Size Three with Distinct Characters
1 parent ac03bb2 commit c958349

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Link: https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
10+
public class Solution {
11+
public int CountGoodSubstrings(string s)
12+
{
13+
StringBuilder sb = new StringBuilder(3);
14+
int counter = 0;
15+
16+
for (int i = 0; i < s.Length; i++)
17+
{
18+
sb.Append(s[i]);
19+
20+
if (sb.Length == 3)
21+
{
22+
if (sb[0] != sb[1] && sb[0] != sb[2] && sb[1] != sb[2])
23+
counter++;
24+
25+
sb.Remove(0, 1);
26+
}
27+
}
28+
29+
return counter;
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /