leetcode-Two Sum
来源:互联网 发布:人的意识与人工智能 编辑:程序博客网 时间:2024/05/17 22:24
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) { int i,j; vector<int> result; int n = numbers.size(); for(i = 0;i < n;i++) for(j = i + 1;j < n;j++) if(target == numbers[i] + numbers[j]) { result.push_back(i+1); result.push_back(j+1); return result; } }};
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
- 各种排序算法的稳定性和时间复杂度小结
- 如何破解验证码之实战篇
- iOS 数据库FMDN 数据库的增 删 改 查 的 的基本操作
- css hack 总结
- 回文数
- leetcode-Two Sum
- mysql5.6.10安装常见问题
- VB.net学习笔记之手柄控制:System.Runtime.InteropServices
- R中面向对象S3
- 批处理编译 *.sln 工程
- 模拟银行管理系统
- DWR的使用
- C#开发微信门户及应用(17)-微信企业号的通讯录管理开发之部门管理
- Cocos2d-x之 CCDirector-->CCDisplayLinkDirector