Skip to content

Commit 1e7dbef

Browse files
committed
repeated_dna_sequences
1 parent 4e5ef50 commit 1e7dbef

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
152152
#### [173. Binary Search Tree Iterator](https://github.com/hitzzc/go-leetcode/tree/master/binary_search_tree_iterator)
153153
#### [174. Dungeon Game](https://github.com/hitzzc/go-leetcode/tree/master/dungeon_game)
154154
#### [179. Largest Number](https://github.com/hitzzc/go-leetcode/tree/master/largest_number)
155+
#### [187. Repeated DNA Sequences](https://github.com/hitzzc/go-leetcode/tree/master/repeated_dna_sequences)
155156

156157

157158

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package repeated_dna_sequences
2+
3+
func findRepeatedDnaSequences(s string) []string {
4+
m := map[string]int{}
5+
rets := []string{}
6+
for i := 0; i <= len(s)-10; i++ {
7+
sub := string(s[i : i+10])
8+
m[sub]++
9+
if m[sub] == 2 {
10+
rets = append(rets, sub)
11+
}
12+
}
13+
return rets
14+
}

0 commit comments

Comments
 (0)