[抄题]:
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
Example:
Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"Output: ["AAAAACCCCC", "CCCCCAAAAA"]
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
- set转成arraylist直接放到括号里就行了
[奇葩corner case]:
[思维问题]:
[英文数据结构或算法,为什么不用别的数据结构或算法]:
10个数,从开始算,加到9就可以了。
for (int i = 0; i + 9 < s.length(); i++)
.substring包左不包右,所以必须写十位数。但是inde
String ten = s.substring(i, i + 10);
beginIndex =< str的值 < endIndex
[一句话思路]:
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
- set的判断语句 没加就自己自动加 没必要再写一遍
- set用add,map用put
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
set就是判重,一个不够用可以用两个
[复杂度]:Time complexity: O(n) Space complexity: O(n)
[算法思想:迭代/递归/分治/贪心]:
[关键模板化代码]:
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
[代码风格] :
[是否头一次写此类driver funcion的代码] :
[潜台词] :
class Solution {public List<String> findRepeatedDnaSequences(String s) { //ini: two setsList<String> result = new ArrayList<String>();Set<String> seen = new HashSet<String>();Set<String> ten = new HashSet<String>();//ccif (s.length() == 0) return result;//for loop: get substringfor (int i = 0; i + 9 < s.length(); i++) {String str = s.substring(i, i+ 10);if (!seen.add(str)) ten.add(str);}//returnreturn new ArrayList(ten);} }