当前位置:网站首页>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;
}
};
边栏推荐
- Student course selection system (curriculum design of Shandong Agricultural University)
- How to choose the right kubernetes storage plug-in? (09)
- Sqlserver queries which indexes are underutilized
- LeetCode 1. 两数之和
- unity Hub 登录框变得很窄 无法登录
- sim2real环境配置教程
- Original God 2.6 server download and installation tutorial
- A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
- sql解决连续登录问题变形-节假日过滤
- Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification
猜你喜欢
随机推荐
Yyds dry goods inventory student attendance system based on QT design
Bib | graph representation based on heterogeneous information network learning to predict drug disease association
Summary | three coordinate systems in machine vision and their relationships
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
机器学习-感知机模型
618深度複盤:海爾智家的制勝方法論
Does bone conduction earphone have external sound? Advantages of bone conduction earphones
La boîte de connexion du hub de l'unit é devient trop étroite pour se connecter
Leetcode --- longest public prefix
Maui learning road (III) -- in depth discussion of winui3
mysql数据库mysqldump为啥没有创建数据库的语句
What is Amazon keyword index? The consequences of not indexing are serious
LeetCode 1. 两数之和
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
Aujourd'hui dans l'histoire: Alipay lance le paiement par code à barres; La naissance du père du système de partage du temps; La première publicité télévisée au monde...
Practice of traffic recording and playback in vivo
What is the difference between self attention mechanism and fully connected graph convolution network (GCN)?
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 releases | geek headlines
Mobile web development learning notes - Layout








