Skip to content

Commit 90a99bf

Browse files
committed
[Function add]
1, Add leetcode solution.
1 parent 82eb65c commit 90a99bf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@
333333

334334
[185. Department Top Three Salaries](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/185.%20Department%20Top%20Three%20Salaries.md)
335335

336+
[187. Repeated DNA Sequences](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/187.%20Repeated%20DNA%20Sequences.md)
337+
336338
## Algorithm(4th_Edition)
337339
Reading notes of book Algorithm(4th Algorithm),ISBN: 9787115293800.
338340
All java realization codes are placed in different packages.

leetcode/187. Repeated DNA Sequences.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,27 @@ class Solution {
5555
return new ArrayList<String>(repeat);
5656
}
5757
}
58+
```
59+
60+
### 二刷
61+
1. 最开始没有想到用两个Set,于是用了Map来记录出现的序列。
62+
```Java
63+
class Solution {
64+
public List<String> findRepeatedDnaSequences(String s) {
65+
List<String> result = new LinkedList<>();
66+
Map<String, Integer> map = new HashMap<>();
67+
if(s == null || s.length() < 10) return result;
68+
int len = s.length();
69+
for(int i = 0; i <= len - 10; i++){
70+
String sub = s.substring(i, i + 10);
71+
if(!map.containsKey(sub)){
72+
map.put(sub, 1);
73+
}else if(map.get(sub) == 1){
74+
result.add(sub);
75+
map.put(sub, map.get(sub) + 1);
76+
}else continue;
77+
}
78+
return result;
79+
}
80+
}
5881
```

0 commit comments

Comments
 (0)