Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
34 lines (26 loc) · 944 Bytes

File metadata and controls

34 lines (26 loc) · 944 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
// Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
// For example,
// Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT",
// Return:
// ["AAAAACCCCC", "CCCCCAAAAA"].
// Hide Company Tags LinkedIn
// Hide Tags Hash Table Bit Manipulation
/**
* @param {string} s
* @return {string[]}
*/
var findRepeatedDnaSequences = function(s) {
var hash = {};
var result = [];
for(var i = 10; i <= s.length; i++) {
var substr = s.substring(i - 10, i);
if(hash[substr] === undefined) {
hash[substr] = 1;
} else if(hash[substr] === 1) {
hash[substr]++;
result.push(substr);
}
}
return result;
};
Morty Proxy This is a proxified and sanitized view of the page, visit original site.