当前位置:网站首页>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
边栏推荐
- One plus six brushes into Kali nethunter
- Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
- 当产业互联网时代真正发展完善之后,将会在每一个场景见证巨头的诞生
- 【LeetCode】88. Merge two ordered arrays
- Win:使用 PowerShell 检查无线信号的强弱
- What is the length of SHA512 hash string- What is the length of a hashed string with SHA512?
- node工程中package.json文件作用是什么?里面的^尖括号和~波浪号是什么意思?
- Outlook: always prompt for user password
- Wechat applet: Xingxiu UI v1.5 WordPress system information resources blog download applet wechat QQ dual end source code support WordPress secondary classification loading animation optimization
- 小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
猜你喜欢

增量备份 ?db full

微信小程序:最新wordpress黑金壁纸微信小程序 二开修复版源码下载支持流量主收益

Win: use shadow mode to view the Desktop Session of a remote user

After reading the average code written by Microsoft God, I realized that I was still too young

Win: use PowerShell to check the strength of wireless signal

Game 280 of leetcode week

微信小程序:微群人脉微信小程序源码下载全新社群系统优化版支持代理会员系统功能超高收益

Restful Fast Request 2022.2.1发布,支持cURL导入

Async/await you can use it, but do you know how to deal with errors?

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
随机推荐
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Win:将一般用户添加到 Local Admins 组中
Wechat applet: Xingxiu UI v1.5 WordPress system information resources blog download applet wechat QQ dual end source code support WordPress secondary classification loading animation optimization
The server time zone value ‘� й ��� ʱ 'is unrecognized or representatives more than one time zone【
当产业互联网时代真正发展完善之后,将会在每一个场景见证巨头的诞生
Phpstrom setting function annotation description
A simple SSO unified login design
Unified blog writing environment
MySQL backup and recovery + experiment
PHP Basics - detailed explanation of DES encryption and decryption in PHP
Win: use PowerShell to check the strength of wireless signal
Comment mettre en place une équipe technique pour détruire l'entreprise?
batchnorm. Py this file single GPU operation error solution
Expansion operator: the family is so separated
What sparks can applet container technology collide with IOT
Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
Change the background color of a pop-up dialog
Huawei machine test question: longest continuous subsequence
runc hang 导致 Kubernetes 节点 NotReady
Nebula Importer 数据导入实践