-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
33 lines (32 loc) · 819 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
namespace CountSubstrings
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
static int CountLetters(string S)
{
var distinctSubs= new List<int>();
int li = 0, hi = 0;
while (hi < S.Length)
{
if (S[li] == S[hi])
hi++;
else
{
distinctSubs.Add(hi - li);
li = hi;
}
}
distinctSubs.Add(hi - li);
var res = 0;
foreach (var distinctSub in distinctSubs)
res += (1 + distinctSub) * distinctSub / 2;
return res;
}
}
}