leetcode 日经贴,Cpp code -Repeated DNA Sequences
2015-08-10 14:46
603 查看
Repeated DNA Sequences
class Solution { public: int getnum(char ch) { int ret = 0; switch(ch) { case 'A': ret = 0; break; case 'C': ret = 1; break; case 'G': ret = 2; break; case 'T': ret = 3; break; default: ret = 0; } return ret; } vector<string> findRepeatedDnaSequences(string s) { vector<string> ans; int n = s.length(); if (n <= 10) { return ans; } int base = 4, m = 0, highbase = (1 << 18); for (int i = 0; i < 10; ++i) { m = m * base + getnum(s[i]); } unordered_map<int, int> mp; mp[m] = 1; for (int i = 10; i < n; ++i) { m -= highbase * getnum(s[i - 10]); m = m * base + getnum(s[i]); if (mp.find(m) != mp.end()) { if (mp[m] == 1) { mp[m] = -1; ans.push_back(s.substr(i - 9, 10)); } } else { mp[m] = 1; } } return ans; } };
相关文章推荐
- warning LNK4075: 忽略”/EDITANDCONTINUE”(由于”/INCREMENTAL:NO”规范)
- 知识点五:BluetoothAdapter类分析
- HDU 1503(Advanced Fruits)最长公共子序列+路径记录
- IOS开发—UIScrollView自动布局
- Android BLE开发之BluetoothGatt status 133
- iOS学习笔记:UISearchBar使用
- 由 uiautomator 二次开发得到的启发以及完善
- UVA - 11995 - I Can Guess the Data Structure!(栈、队列、优先队列)
- Snail—UI学习之工具栏UIToolBar
- 【HDU5357】Easy Sequence 题解(栈的应用)
- 如何调整UIPickerView,UISwitch等无法通过frame调整大小的大小
- iOS UILable根据文本内容自适应高度
- Ueditor .net版安装配置打开项目的源代码傻瓜版教程 亲测~
- UI控件切圆角
- IOS开发UI篇--IOS动画(Core Animation)总结
- DevExpress控件库---MarqueeProgressBarControl控件和ProgressBarControl控件
- substring() intValue() valueOf()
- iOS开发UI篇--iOS动画(Core Animation)总结
- UI资源索引
- leetCode #232 Implement Queue using Stacks