-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution187.cs
36 lines (32 loc) · 922 Bytes
/
Solution187.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
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution187
{
/// <summary>
/// 187. Repeated DNA Sequences - Medium
/// <a href="https://leetcode.com/problems/repeated-dna-sequences">See the problem</a>
/// </summary>
public IList<string> FindRepeatedDnaSequences(string s)
{
var sequences = new Dictionary<string, int>();
var result = new List<string>();
for (int i = 0; i <= s.Length - 10; i++)
{
var sequence = s.Substring(i, 10);
if (sequences.ContainsKey(sequence))
{
sequences[sequence]++;
if (sequences[sequence] == 2)
{
result.Add(sequence);
}
}
else
{
sequences[sequence] = 1;
}
}
return result;
}
}