Leetcode 1. Two Sum (Easy) (cpp)
来源:互联网 发布:牛顿环和劈尖实验数据 编辑:程序博客网 时间:2024/06/01 08:57
Leetcode 1. Two Sum (Easy) (cpp)
Tag: Array, Hash Table
Difficulty: Easy
/*1. Two Sum (Easy)Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].UPDATE (2016/2/13):The return format had been changed to zero-based indices. Please read the above updated description carefully.*/class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> mapping; for (int i = 0; i < nums.size(); i++) { int gap = target - nums[i]; if (mapping.count(gap)) { return {i, mapping[gap]}; } mapping[nums[i]] = i; } return {}; }};
0 0
- Leetcode 1. Two Sum (Easy) (cpp)
- leetcode 1. Two Sum [Easy]
- LeetCode 1. Two Sum (Easy)
- Leetcode 371. Sum of Two Integers (Easy) (cpp)
- Leetcode[Easy] - Two Sum
- 【Leetcode】Two sum(easy)
- leetcode Two Sum easy
- Leetcode 1. Two Sum (Easy) (java)
- Leetcode #1 Two Sum (easy)
- Leetcode #1 - Two Sum - Easy
- 【Easy】1. Two Sum
- 1. Two Sum easy
- 1. Two Sum (Easy)
- 1.[easy] Two Sum
- Leetcode 231. Power of Two (Easy) (cpp)
- Leetcode 112. Path Sum (Easy) (cpp)
- Leetcode 437. Path Sum III (Easy) (cpp)
- LeetCode解题报告 1. Two Sum[easy]
- 51nod 1190 最小公倍数之和 V2(莫比乌斯反演)
- 【Android基础知识】AsyncTask基本使用
- 【目标检测】Faster RCNN算法详解
- 字符类的数字转化成数字类型
- sql server存储过程循环调用
- Leetcode 1. Two Sum (Easy) (cpp)
- 对面向对象的理解和this static的理解
- Android 提示超出64K的解决办法
- mysql 外键
- POJ 3281 Dining
- FZU 2180 骑士 (双向BFS)
- Android 文件下载
- c#中Monitor的使用
- PHP使用非递归方式实现猴子找大王算法