-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution830.cs
44 lines (38 loc) · 980 Bytes
/
Solution830.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
38
39
40
41
42
43
44
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution830
{
/// <summary>
/// 830. Positions of Large Groups - Easy
/// <a href="https://leetcode.com/problems/positions-of-large-groups">See the problem</a>
/// </summary>
public IList<IList<int>> LargeGroupPositions(string s)
{
var result = new List<IList<int>>();
var n = s.Length;
var start = 0;
var count = 1;
for (var i = 1; i < n; i++)
{
if (s[i] == s[i - 1])
{
count++;
}
else
{
if (count >= 3)
{
result.Add(new List<int> { start, i - 1 });
}
start = i;
count = 1;
}
}
if (count >= 3)
{
result.Add(new List<int> { start, n - 1 });
}
return result;
}
}