当前位置:网站首页>【STL】Map &unordered_map
【STL】Map &unordered_map
2022-07-24 05:15:00 【rejudge】
- Map与unordered_map
- Map用法整理
- unordered_map用法整理
- 题目 LeetCode 1.3.
//记得引入头文件
#include<unordered_map>
//引入头文件出错,可尝试这个
#include<iostream>
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
int main()
{
unordered_map<int,int> heap;//key,value
heap[0]='a';
heap[1]='b';
heap[2]='c';
//删除key 成功1
cout<<heap.erase(2)<<endl;
//判断key是否存在 在1不在0
//查找的是key,也可看为<val,key>,查找元素val存不存在,进而查找元素对应的key
cout<<(heap.find(0) !=heap.end())<<endl;
//或者
cout<<heap.count(0);
return 0;
}
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> heap; //<值,下标>
for(int i=0;i<nums.size();i++)
{
int r=target-nums[i];
if(heap.count(r)) return {
heap[r],i};
heap[nums[i]]=i;
}
return {
};
}
};
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> heap;
int res=0;
for(int i=0,j=0;i<s.size();i++)
{
heap[s[i]]++;
while(heap[s[i]]>1)
{
heap[s[j]]--;
j++;
}
res=max(res, i-j+1);
}
return res;
}
};
边栏推荐
- Chapter5 foundation of deep learning
- DHCP principle and configuration
- jdbc封装一个父类减少代码重复
- 熊市抄底指南
- [basic 8] - processes and threads
- SSM整合
- IDEA:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.
- Un7.23: how to install MySQL on linix?
- un7.23:如何在linix上安装MySQL?
- How can NFT, whose stars enter the market against the market, get out of the independent market?
猜你喜欢

Bear market bottoming Guide

web开发

Hcip day 3 - mGRE experiment

Markov random field: definition, properties, maximum a posteriori probability problem, energy minimization problem

Globally and locally consistent image completion paper notes

Data annotation learning summary

利用a*启发式搜索解决迷宫寻路问题

Performance test process
![[advanced mathematics] the difference between differentiable and differentiable functions](/img/32/ead52f0d451e3c07a22c7a107fc8b9.jpg)
[advanced mathematics] the difference between differentiable and differentiable functions

On the dilemma faced by non transferable reputation points NFT SBTS
随机推荐
股票价格走势的行业关联性
The network NN can calculate the NTCP provided by the host system
Relational database 10 minutes to understand MySQL
CentOS 7安装Mysql5.6.37
线程的介绍
Source code compilation!!
[Basic 6] - encapsulation and inheritance of classes, objects and classes
Blue Bridge Cup 31 day sprint 21 day (C language)
。 Single type digital sensing is an application 0 Up address is at the factory
【深度学习】(三)图像分类
Learning pyramid context encoder network for high quality image painting paper notes
Problems encountered in configuring Yum source
1. Input a 100 point score from the keyboard and output its grade according to the following principles: score ≥ 90, Grade A; 80 ≤ score < 90, grade B; 70 ≤ score < 80, grade C; 60 ≤ score < 70, grade
Image painting for irregular holes using partial revolutions paper notes
Bear market bottoming Guide
C#表格数据去重
C primer plus learning notes - 6. Arrays and pointers
MySQL transaction and its problems and isolation level
1、基于增量式生成遮挡与对抗抑制的行人再识别
Ren Xudong, chief open source liaison officer of Huawei: deeply cultivate basic software open source and jointly build the root technology of the digital world