当前位置:网站首页>187. Repeated DNA sequence - with unordered_ Map basic content
187. Repeated DNA sequence - with unordered_ Map basic content
2022-07-05 01:42:00 【The_ Dan】
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
unordered_map<string, int> map;
vector<string> vecStr;
if(s.size()<=10) // The sample may not be longer than 10
return vecStr;
for(int i = 0; i <= s.size() - 10; i++){
// Count the number of each occurrence
string str = s.substr(i, 10);
if(map.find(str) != map.end())
map.find(str)->second++;
else{
map.insert(pair<string, int>(str, 1));
}
}
for (auto i = map.begin(); i != map.end(); i++){
// The frequency of occurrence is greater than 1 Times added
if(i -> second > 1)
vecStr.push_back(i -> first);
}
return vecStr;
}
};
Accepted
31/31 cases passed (44 ms)
Your runtime beats 77.64 % of cpp submissions
Your memory usage beats 23.79 % of cpp submissions (22.9 MB)
unordered_map The iterator of is a pointer , Point to this element , Get its value through an iterator .
1 unordered_map<Key,T>::iterator it;
2 (*it).first; // the key value (of type Key)
3 (*it).second; // the mapped value (of type T)
4 (*it); // the "element value" (of type pair<const Key,T>)
Its key values are iterator's first and second attribute .
1 it->first; // same as (*it).first (the key value)
2 it->second; // same as (*it).second (the mapped value)
Member functions :
================= iterator =========================
begin Returns the iterator pointing to the beginning of the container (iterator)
end The position of the iterator at the end of the container points to
cbegin Returns a constant iterator pointing to the beginning of the container (const_iterator)
cend Returns the constant iterator pointing to the end of the container
================= Capacity ================
size Returns the number of valid elements
max_size return unordered_map The maximum number of elements supported
empty Determine whether it is null
================= Element access =================
operator[] Access elements
at Access elements
================= Element modification =================
insert Insert elements
erase Remove elements
swap Exchange content
clear Empty content
emplace Construct and insert an element
emplace_hint Follow the prompts to construct and insert an element
================ operation =========================
find Find elements by giving a primary key , Did not find : return unordered_map::end
count Returns the number of elements that match a given primary key
equal_range The return value matches the range of elements of a given search value
================ Buckets ======================
bucket_count Return slot (Bucket) Count
max_bucket_count Returns the maximum number of slots
bucket_size Return slot size
bucket Returns the serial number of the slot where the element is located
load_factor Returns the load factor , It's an element tank (Bucket) The maximum number of elements
max_load_factor Returns or sets the maximum load factor
rehash Set the number of slots
reserve Request to change container capacity
边栏推荐
- Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
- Global and Chinese market of optical densitometers 2022-2028: Research Report on technology, participants, trends, market size and share
- 微信小程序:全新独立后台月老办事处一元交友盲盒
- Are you still writing the TS type code
- One plus six brushes into Kali nethunter
- Wechat applet: exclusive applet version of the whole network, independent wechat community contacts
- Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
- Global and Chinese markets for industrial X-ray testing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and mobile phones can also easily read literature
- MySQL backup and recovery + experiment
猜你喜欢

MySQL REGEXP:正则表达式查询

One plus six brushes into Kali nethunter

Complex, complicated and numerous: illustration of seven types of code coupling

How to safely eat apples on the edge of a cliff? Deepmind & openai gives the answer of 3D security reinforcement learning

Roads and routes -- dfs+topsort+dijkstra+ mapping

Basic operation of database and table ----- the concept of index
![Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio](/img/e8/de158982788fc5bc42f842b07ff9a8.jpg)
Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio

Actual combat simulation │ JWT login authentication
![[OpenGL learning notes 8] texture](/img/77/a4a784a535ea6f4c2382857b266cec.jpg)
[OpenGL learning notes 8] texture

To sort out messy header files, I use include what you use
随机推荐
Kibana installation and configuration
One click generation and conversion of markdown directory to word format
Restful fast request 2022.2.1 release, support curl import
es使用collapseBuilder去重和只返回某个字段
Basic operations of database and table ----- create index
Blue Bridge Cup Square filling (DFS backtracking)
Numpy library introductory tutorial: basic knowledge summary
PowerShell: use PowerShell behind the proxy server
MATLB|多微电网及分布式能源交易
Mysql database | build master-slave instances of mysql-8.0 or above based on docker
How to build a technical team that will bring down the company?
Are you still writing the TS type code
無心劍英譯席慕容《無怨的青春》
Yyds dry inventory swagger positioning problem ⽅ formula
Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio
Async/await you can use it, but do you know how to deal with errors?
Database postragesq peer authentication
Application and Optimization Practice of redis in vivo push platform
I use these six code comparison tools
Win:使用组策略启用和禁用 USB 驱动器