leetCode Two Sum
来源:互联网 发布:327国债事件 知乎 编辑:程序博客网 时间:2024/06/06 01:55
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
class Solution {public: vector<int> twoSum(vector<int> &numbers, int target) { map<int, int> m; vector<int> rst; for(int i = 0; i < numbers.size(); i++) { map<int, int>::iterator it = m.find(target - numbers[i]); if(it == m.end()) { m[numbers[i]] = i + 1; continue; } rst.push_back(it->second); rst.push_back(i + 1); return rst; } }};
0 0
- 【Leetcode】Two Sum (Sum)
- 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
- [LeetCode]Two Sum
- leetcode Two Sum
- [Leetcode] Two Sum
- [leetcode] Two Sum
- LeetCode - Two Sum
- leetcode之Two Sum
- LeetCode | Two Sum
- 转炉流程轴承钢技术的开发是轴承钢的冶炼时间缩短
- 双缓冲绘图
- How tomcat works 读书笔记十五 Digester库 下
- ubuntu下无法编译ruby-2.1.5提示something wrong with CFLAGS -arch x86_64
- 程序中的三国
- leetCode Two Sum
- 下载Ext JS 5.1 gpl版本的方法
- 简单的用户登录验证
- sql 字段左边去掉0
- iOS小问题---Your build settings specify a provisioning profile with the UUID的问题
- 关于android.permission.GET_TASKS
- [instrument]time profile
- DVB-EIT
- 字母数字穷举排列组合域名,位数递增,网络爬虫,网页抓取