当前位置:网站首页>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;
}
};
边栏推荐
- Download blender on Alibaba cloud image station
- Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
- [fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)
- Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)
- Effectively use keywords to increase Amazon sales
- 绝对真理和相对真理思考
- Does bone conduction earphone have external sound? Advantages of bone conduction earphones
- Sqlserver queries which indexes are underutilized
- LeetCode 2. 两数相加
- According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
猜你喜欢

Kubernetes family container housekeeper pod online Q & A?
![OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation](/img/8b/36be3191a7d71f4a8c8181eaed8417.jpg)
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation

Does bone conduction earphone have external sound? Advantages of bone conduction earphones

电脑设备打印机驱动安装失败如何解决
![[fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)](/img/c7/1949894e106036d2b412bcd6f70245.jpg)
[fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)

SSM整合-异常处理器及项目异常处理方案

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...

理想之光不灭

MySQL min() finds the minimum value under certain conditions, and there are multiple results

忆当年高考|成为程序员的你,后悔了吗?
随机推荐
LeetCode 4. 寻找两个正序数组的中位数(hard)
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...
Classic quotations
绝对真理和相对真理思考
sql解决连续登录问题变形-节假日过滤
Set the background picture in the idea (ultra detailed)
sim2real环境配置教程
大廠面試總結大全
Unity Json 编写
Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
unity Hub 登錄框變得很窄 無法登錄
Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
Unity使用UGUI设置一个简单多级水平方向下拉菜单(不需要代码)
How to solve the failure of printer driver installation of computer equipment
A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
The light of ideal never dies
潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
TypeScript数组乱序输出
Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation