-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Create 0187-repeated-dna-sequences.js #2557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
97d9ab2
18467a0
047feab
3c1231a
81ba7c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * https://leetcode.com/problems/repeated-dna-sequences/ | ||
| * Hashing | ||
| * s = the number of letters in the sequance. In our case it's 10. so the time complexity would be 10*n which boils down to n. | ||
| * Time O(s*n) | Space O(n) | ||
| * @param {string} s | ||
| * @return {string[]} | ||
| */ | ||
|
|
||
| var findRepeatedDnaSequences = function(s) { | ||
|
|
||
| const sequanceStack = new Set(); | ||
| let resultStack = new Set(); | ||
|
|
||
| for(let i = 0; i < s.length; i++) { | ||
| const subSequance = getSubSequance(s,i,10); | ||
| if(sequanceStack.has(subSequance)) { | ||
| resultStack.add(subSequance); | ||
| } else { | ||
| sequanceStack.add(subSequance); | ||
| } | ||
| } | ||
|
|
||
| resultStack = [...resultStack]; | ||
| return resultStack; | ||
| }; | ||
|
|
||
| function getSubSequance(s,i,len) { | ||
| return s.slice(i, i + len); | ||
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable names are misleading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my bad. Sorry. I updated the variables.