problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::repeated_dna_sequences::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< string > findRepeatedDnaSequences (string s)
 

详细描述

在文件 leetcode.h2686 行定义.

成员函数说明

◆ findRepeatedDnaSequences()

vector< string > leetcode::repeated_dna_sequences::Solution::findRepeatedDnaSequences ( string  s)
static

在文件 leetcode.cpp7274 行定义.

7274 {
7275 vector<unsigned short> vec(s.length());
7276 for(int i = 0; i < s.length(); i++) {
7277 switch(s[i]) {
7278 case 'A':
7279 vec[i] = 0;
7280 break;
7281 case 'C':
7282 vec[i] = 1;
7283 break;
7284 case 'G':
7285 vec[i] = 2;
7286 break;
7287 case 'T':
7288 vec[i] = 3;
7289 break;
7290 }
7291 }
7292 unsigned hsv = 0;
7293 if(s.length() < 10) {
7294 return {};
7295 }
7296 unordered_map<unsigned, string> um;
7297 unordered_map<unsigned, unsigned> cnt;
7298 for(int i = 0; i < 10; i++) {
7299 hsv *= 4;
7300 hsv += vec[i];
7301 }
7302 um[hsv] = s.substr(0, 10);
7303 cnt[hsv] = 1;
7304 const unsigned f = 262144;
7305 for(int i = 10; i < s.length(); i++) {
7306 hsv -= vec[i - 10] * f;
7307 hsv *= 4;
7308 hsv += vec[i];
7309 um[hsv] = s.substr(i - 9, 10);
7310 cnt[hsv]++;
7311 }
7312 vector<string> ans;
7313 for(auto &[k, v]: um) {
7314 if(cnt[k] > 1) {
7315 ans.emplace_back(v);
7316 }
7317 }
7318 return ans;
7319 }
int vec[100010]
Definition: pat.cpp:5095

引用了 pat::a::a7_2::vec.


该类的文档由以下文件生成: