Skip to content

Commit 71ccd34

Browse files
🧮 Day 17
1 parent 5abf453 commit 71ccd34

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
1. [Rotate Array](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/561/week-3-october-15th-october-21st/3496/) ➡️ [CPP Solution](Week3/rotate.cpp)
3030
2. [Search a 2D Matrix](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/561/week-3-october-15th-october-21st/3497/) ➡️ [CPP Solution](Week3/searchMatrix.cpp)
31+
3. [Repeated DNA Sequences](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/561/week-3-october-15th-october-21st/3498/) ➡️ [CPP Solution](Week3/findRepeatedDnaSequences.cpp)
3132

3233
## Week 4 🚧
3334

Week3/findRepeatedDnaSequences.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
vector<string> findRepeatedDnaSequences(string s) {
4+
unordered_map<string, int> seen;
5+
int n = s.size();
6+
vector<string> res;
7+
8+
if(n < 10) return {};
9+
10+
for(int i = 0; i + 10 <= n; ++i) {
11+
string sub = s.substr(i, 10);
12+
seen[sub]++;
13+
14+
if(seen[sub] == 2) {
15+
res.push_back(sub);
16+
}
17+
}
18+
19+
return res;
20+
}
21+
};

0 commit comments

Comments
 (0)