当前位置:网站首页>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;
}
};
边栏推荐
- 618深度複盤:海爾智家的制勝方法論
- Yyds dry inventory uses thread safe two-way linked list to realize simple LRU cache simulation
- Bib | graph representation based on heterogeneous information network learning to predict drug disease association
- Understand the key technology of AGV -- the difference between laser slam and visual slam
- PCL least median square method fitting plane
- Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
- 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...
- PyC file decompile
- (practice C language every day) the sum of the nearest three numbers
- Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Routing mode: hash and history mode

电脑设备打印机驱动安装失败如何解决

Yyds dry goods inventory student attendance system based on QT design

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

总结|机器视觉中三大坐标系及其相互关系

⌈ 2022 ⌋ how to use webp gracefully in projects

Download blender on Alibaba cloud image station

SSM integration exception handler and project exception handling scheme

潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
随机推荐
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
机器学习-感知机模型
数学分析_笔记_第6章:一元函数的Riemann积分
[fluent] dart data type boolean type (boolean type definition | logical operation)
Route service grid traffic through two-level gateway design
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
MySQL min() finds the minimum value under certain conditions, and there are multiple results
Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)
Vscade set multi line display of tab
Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
总结|机器视觉中三大坐标系及其相互关系
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
Typescript array out of order output
The difference and usage of calloc, malloc and realloc functions
历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
LeetCode 6. Z 字形变换 (N字形变换)
[Yu Yue education] reference materials of sensing and intelligent control technology of Nanjing University of Technology
Vscode设置标签页多行显示
Sqlserver queries which indexes are underutilized