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.

For example,

Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT",

Return:
["AAAAACCCCC", "CCCCCAAAAA"].

思路I:遍历string,每次截取10个字符,判断出现次数。

Result: Time Limit Exceeded

思路II:字符数较少=>用数字表示字符=>用bitmap来表示字符串,好处:节省空间

比如本题只可能出现4种字符=>可表示为0,1,2,3,即可以用2bits来表示=>字符原本一个字符占1 byte = 8 bits,现在只要2 bits

class Solution {
public:
int getVal(char ch) {
if (ch == 'A') return ;
if (ch == 'C') return ;
if (ch == 'G') return ;
if (ch == 'T') return ;
} vector<string> findRepeatedDnaSequences(string s) {
int sLen = s.length();
unsigned int val=;
char mp[*]={};
vector<string> ret;
string str; if(sLen < ) return ret; for(int i = ; i < ; i++){
val <<=;
val |= getVal(s[i]);
} for(int i = ; i < sLen; i++){
val <<= ;
val |= getVal(s[i]);
val &= 0xFFFFF;
if(++mp[val] == ){
str = s.substr(i-,);
ret.push_back(str);
}
} return ret;
}
};

187. Repeated DNA Sequences (String; Bit)的更多相关文章

  1. [LeetCode] 187. Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  2. leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  3. Java for LeetCode 187 Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  4. 187. Repeated DNA Sequences

    题目: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...

  5. [LeetCode#187]Repeated DNA Sequences

    Problem: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: ...

  6. [LeetCode] 187. Repeated DNA Sequences 解题思路

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  7. 【LeetCode】187. Repeated DNA Sequences

    题目: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...

  8. 187. Repeated DNA Sequences重复的DNA子串序列

    [抄题]: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &qu ...

  9. *187. Repeated DNA Sequences (hashmap, one for loop)(difference between subsequence & substring)

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

随机推荐

  1. Redis 内存溢出过期策略

    1: 设置内存最大值, 如果该主机只作为 redis 服务器, 无其它比较占用资源的服务, 建议设置为内存的 3/4 大小, 单位 B 2: 设置内存溢出解决策略, 推荐 1-5 任选一种, 不推荐 ...

  2. centos7.5安装VirtualBox

    centos7.5安装minikube时要求先安装VirtualBox 1.准备repo文件 [root@localhost yum.repos.d]# pwd /etc/yum.repos.d [r ...

  3. Ubuntu 下安装 Swoole

    环境:Ubuntu16.04 apt-get update apa-get install apache2 php php-pear php-dev mysql-server gcc apache2 ...

  4. PHP单点登陆

    本文主要介绍了利用webservice,session,cookie技术,来进行通用的单点登录系统的分析与设计.具体实现语言为PHP.单点 登录,英文名为Single Sign On,简称为 SSO, ...

  5. offsetof使用小结

    先上例子 #include <stdio.h> #include <stdlib.h> /* offsetof example */ #include <stddef.h ...

  6. hIve—timestamp时间戳问题

    先查看表 timestamp可以转换为标准的时间(精确到秒);https://tool.lu/timestamp/ 这个时间格式用处很多: 多个时间可以使用函数,来切换. 每个用户 产生行为的时候,用 ...

  7. 01_hello world

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. jquery接触初级-----juqery 动画函数

    1. window.onload(), 一次只能保存对一个函数的引用:如果多次调用,他会自动用后面的函数覆盖前面的函数 2.$(document).ready(); 会在现有行为上追加新的行为,这些函 ...

  9. 数据结构:Queue

    Queue设计与实现 Queue基本概念 队列是一种特殊的线性表 队列仅在线性表的两端进行操作 队头(Front):取出数据元素的一端 队尾(Rear):插入数据元素的一端 队列不允许在中间部位进行操 ...

  10. Matplotlib中文乱码问题

    一.找到并修改matplotlibrc文件 进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目录,用记事本打开matplotlibrc文件:找到f ...