forked from TheAlgorithms/C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcc.cs
37 lines (30 loc) · 799 Bytes
/
lcc.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
34
35
36
37
using System;
namespace Example
{
public static partial class StringViewModel
{
public static Tuple<char, int> LongesConsecutiveCharacters(string input)
{
var max_char = input[0];
var max = 1;
var current = 1;
for (var i = 1; i < input.Length; i++)
{
if (input[i] == input[i - 1])
{
current++;
if (current > max)
{
max = current;
max_char = input[i];
}
}
else
{
current = 1;
}
}
return new Tuple<char, int>(max_char, max);
}
}
}