当前位置:网站首页>LeetCode 1. Sum of two numbers
LeetCode 1. Sum of two numbers
2022-07-02 16:40:00 【_ Liu Xiaoyu】
Given an array of integers nums And an integer target value target, Please find... In the array And is the target value target the Two Integers , And return their array subscripts .
You can assume that each input corresponds to only one answer . however , The same element in the array cannot be repeated in the answer .
You can return the answers in any order .
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> re;
unordered_map<int, int> hash; // Record where the number appears
for(int i=0; i<nums.size(); i++)
{
int other = target - nums[i];
if(hash.count(other))
{
re = vector<int>({
hash[other], i});
break;
}
hash[nums[i]] = i;
}
return re;
}
};
边栏推荐
- Yyds dry inventory method of deleting expired documents in batch
- What is normal distribution? What is the 28 law?
- 图书管理系统(山东农业大学课程设计)
- TCP拥塞控制详解 | 2. 背景
- 2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
- 外企高管、连续创业者、瑜伽和滑雪高手,持续迭代重构的程序人生
- Yyds dry inventory uses thread safe two-way linked list to realize simple LRU cache simulation
- TypeScript数组乱序输出
- Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
- Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
What if the win11 app store cannot load the page? Win11 store cannot load page
Download blender on Alibaba cloud image station
Vscade set multi line display of tab
Original God 2.6 server download and installation tutorial
[Yu Yue education] reference materials of sensing and intelligent control technology of Nanjing University of Technology
Take you ten days to easily complete the go micro service series (I)
HMS core machine learning service helps zaful users to shop conveniently
mysql min() 求某条件下最小的值出现多个结果
数据安全产业系列沙龙(三)| 数据安全产业标准体系建设主题沙龙
Data security industry series Salon (III) | data security industry standard system construction theme Salon
随机推荐
(practice C language every day) the sum of the nearest three numbers
What is Amazon keyword index? The consequences of not indexing are serious
Kubernetes family container housekeeper pod online Q & A?
Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
Does bone conduction earphone have external sound? Advantages of bone conduction earphones
Practice of traffic recording and playback in vivo
MySQL min() finds the minimum value under certain conditions, and there are multiple results
Summary of multithreading and thread synchronization knowledge
绝对真理和相对真理思考
Maui learning road (III) -- in depth discussion of winui3
mysql数据库mysqldump为啥没有创建数据库的语句
Multi task prompt learning: how to train a large language model?
曆史上的今天:支付寶推出條碼支付;分時系統之父誕生;世界上第一支電視廣告...
Summary | three coordinate systems in machine vision and their relationships
数学分析_笔记_第6章:一元函数的Riemann积分
Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
大廠面試總結大全
Routing mode: hash and history mode
Text intelligent expansion and contraction control of swiftui text component (tutorial includes source code)
Memory alignment of structure