博文中会简要介绍Leetcode P0187题目分析及解题思路。
“Repeated DNA Sequences”这道题比较基础。利用HashTable可以比较容易地解决这个题目。
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:
根据题目需求我们其实是在给定的字符串s
里寻找长度为10并且重复出现多次的子串。最直接的想法就是我们记录下所有长度为10的子串,利用HashTable来记录每个子串出现的次数,然后次数大于1的子串便是我们想要找的子串。
以下是Java的题解代码实现。
以下是C++的题解代码实现。