Skip to content

Commit ac6fbbf

Browse files
committed
Add solution #187
1 parent be5d419 commit ac6fbbf

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
168|[Excel Sheet Column Title](./0168-excel-sheet-column-title.js)|Easy|
144144
169|[Majority Element](./0169-majority-element.js)|Easy|
145145
179|[Largest Number](./0179-largest-number.js)|Medium|
146+
187|[Repeated DNA Sequences](./0187-repeated-dna-sequences.js)|Medium|
146147
189|[Rotate Array](./0189-rotate-array.js)|Medium|
147148
190|[Reverse Bits](./0190-reverse-bits.js)|Easy|
148149
191|[Number of 1 Bits](./0191-number-of-1-bits.js)|Easy|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 187. Repeated DNA Sequences
3+
* https://leetcode.com/problems/repeated-dna-sequences/
4+
* Difficulty: Medium
5+
*
6+
* The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T':
7+
* - For example, "ACGAATTCCG" is a DNA sequence.
8+
*
9+
* When studying DNA, it is useful to identify repeated sequences within the DNA.
10+
*
11+
* Given a string s that represents a DNA sequence, return all the 10-letter-long sequences
12+
* (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.
13+
*/
14+
15+
/**
16+
* @param {string} s
17+
* @return {string[]}
18+
*/
19+
var findRepeatedDnaSequences = function(s) {
20+
let substring = s.slice(0, 10);
21+
const set = new Set([substring]);
22+
const result = new Set();
23+
24+
for (let i = 10; i < s.length; i++) {
25+
substring = substring.slice(1) + s[i];
26+
if (set.has(substring)) {
27+
result.add(substring);
28+
}
29+
set.add(substring);
30+
}
31+
32+
return [...result];
33+
};

0 commit comments

Comments
 (0)