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

Sign up
Appearance settings

Commit 851fbb4

Browse files
feat: add go,cpp solutions to lc problem: No.0187.Repeated DNA Sequences
1 parent 629366e commit 851fbb4

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

‎solution/0100-0199/0187.Repeated DNA Sequences/README.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,44 @@ var findRepeatedDnaSequences = function(s) {
104104
};
105105
```
106106

107+
### **Go**
108+
109+
```go
110+
func findRepeatedDnaSequences(s string) []string {
111+
cnt := make(map[string]int)
112+
n := len(s) - 10
113+
ans := make([]string, 0)
114+
for i := 0; i <= n; i++ {
115+
sub := s[i : i+10]
116+
cnt[sub]++
117+
if cnt[sub] == 2 {
118+
ans = append(ans, sub)
119+
}
120+
}
121+
return ans
122+
}
123+
```
124+
125+
### **C++**
126+
127+
```cpp
128+
class Solution {
129+
public:
130+
vector<string> findRepeatedDnaSequences(string s) {
131+
map<string, int> cnt;
132+
int n = s.size() - 10;
133+
vector<string> ans;
134+
for (int i = 0; i <= n; ++i) {
135+
string sub = s.substr(i, 10);
136+
if (++cnt[sub] == 2) {
137+
ans.push_back(sub);
138+
}
139+
}
140+
return ans;
141+
}
142+
};
143+
```
144+
107145
### **...**
108146
109147
```

‎solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,44 @@ var findRepeatedDnaSequences = function(s) {
9393
};
9494
```
9595

96+
### **Go**
97+
98+
```go
99+
func findRepeatedDnaSequences(s string) []string {
100+
cnt := make(map[string]int)
101+
n := len(s) - 10
102+
ans := make([]string, 0)
103+
for i := 0; i <= n; i++ {
104+
sub := s[i : i+10]
105+
cnt[sub]++
106+
if cnt[sub] == 2 {
107+
ans = append(ans, sub)
108+
}
109+
}
110+
return ans
111+
}
112+
```
113+
114+
### **C++**
115+
116+
```cpp
117+
class Solution {
118+
public:
119+
vector<string> findRepeatedDnaSequences(string s) {
120+
map<string, int> cnt;
121+
int n = s.size() - 10;
122+
vector<string> ans;
123+
for (int i = 0; i <= n; ++i) {
124+
string sub = s.substr(i, 10);
125+
if (++cnt[sub] == 2) {
126+
ans.push_back(sub);
127+
}
128+
}
129+
return ans;
130+
}
131+
};
132+
```
133+
96134
### **...**
97135
98136
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<string> findRepeatedDnaSequences(string s) {
4+
map<string, int> cnt;
5+
int n = s.size() - 10;
6+
vector<string> ans;
7+
for (int i = 0; i <= n; ++i) {
8+
string sub = s.substr(i, 10);
9+
if (++cnt[sub] == 2) {
10+
ans.push_back(sub);
11+
}
12+
}
13+
return ans;
14+
}
15+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
func findRepeatedDnaSequences(s string) []string {
2+
cnt := make(map[string]int)
3+
n := len(s) - 10
4+
ans := make([]string, 0)
5+
for i := 0; i <= n; i++ {
6+
sub := s[i : i+10]
7+
cnt[sub]++
8+
if cnt[sub] == 2 {
9+
ans = append(ans, sub)
10+
}
11+
}
12+
return ans
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /