当前位置:网站首页>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;
}
};
边栏推荐
- [fluent] dart data type boolean type (boolean type definition | logical operation)
- [fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)
- 虚假的暑假
- 做机器视觉哪个软件好?
- AcWing 300. Task arrangement
- 理想之光不灭
- Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
- Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
- LeetCode 2. 两数相加
- LeetCode 5. 最长回文子串
猜你喜欢

The login box of unity hub becomes too narrow to log in

A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits

流批一体在京东的探索与实践

Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation

Everyone Xinfu builds: a one-stop intelligent business credit service platform

大廠面試總結大全

SQL solves the problem of continuous login deformation holiday filtering

Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation

JS learning notes - first acquaintance

Mobile web development learning notes - Layout
随机推荐
ROW_ NUMBER()、RANK()、DENSE_ Rank difference
PyC file decompile
sim2real环境配置教程
路由模式:hash和history模式
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
JS learning notes - data types
触发器:Mysql实现一张表添加或删除一条数据,另一张表同时添加
unity Hub 登录框变得很窄 无法登录
Kubernetes family container housekeeper pod online Q & A?
大厂面试总结大全
做机器视觉哪个软件好?
忆当年高考|成为程序员的你,后悔了吗?
Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm
[fluent] dart data type boolean type (boolean type definition | logical operation)
虚假的暑假
Practice of traffic recording and playback in vivo
Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
SQL solves the problem of continuous login deformation holiday filtering
潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)