leetcode(E)two sum
来源:互联网 发布:linux文件复制命令 编辑:程序博客网 时间:2024/06/05 21:14
- Two Sum QuestionEditorial Solution My Submissions
Total Accepted: 344929
Total Submissions: 1217901
Difficulty: Easy
Contributors: Admin
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.
Subscribe to see which companies asked this question
Show Tags
Show Similar Problems
代码:
class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { multimap<int,int> m;vector<int> v; for(int i=0;i<nums.size();++i){ if(m.count(target-nums[i])&&m[target-nums[i]]!=i){ v.push_back(i); v.push_back(m[target-nums[i]]); return v; } } }};
末尾挨个给v push_back其实没有比要,直接return (i, m[target-nums[i])
0 0
- leetcode(E)two sum
- leetcode(E) two sum
- LeetCode-E-Two Sum
- LeetCode-E-Two Sum II
- 1. Two Sum【E】【59+25】【leetcode】
- 【leetcode】371. Sum of Two Integers【E】
- 【Leetcode】Two Sum (Sum)
- leetcode(E)two sumII
- LeetCode: Two Sum
- LeetCode: Two Sum
- [Leetcode] Two Sum
- LeetCode : Two Sum
- Leetcode: Two Sum
- leetcode 46: Two Sum
- [LeetCode] Two Sum
- LeetCode 1 - Two Sum
- Leetcode : Two Sum
- 【leetcode】Two Sum
- 鼠标滚轮事件
- spring学习总结(五):IOC & DI 配置 Bean 之自动装配及bean之间的关系
- level遍历102. Binary Tree Level Order Traversal
- 如果有人让你推荐编程技术书,请叫他看这个列表
- 【bzoj 1179】[Apio2009]Atm(Tarjan+spfa)
- leetcode(E)two sum
- [hdu 5973 Game of Taking Stones] Wythoff Game+大数运算
- Linux UDP网络编程
- 数据结构中的树
- 总结37
- HDU 5978 icpc 大连 To begin or not to begin
- Unity3D自学笔记——UGUI背包系统(二)UI设计实现及数据绑定
- POJ 3133 Manhattan Wiring
- LeetCode(55)Jump Game