[LeetCode]1. Two Sum
2017-02-03 09:32
351 查看
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, and you may not use the same element twice.
My solution
Another possible solution
*Use hashtable for efficiency
You may assume that each input would have exactly one solution, and you may not use the same element twice.
My solution
class Solution { public: vector<int> result; for (int i = 0; i < nums.size(); i++) { for (int j = i + 1; j < nums.size(); j++) { if (nums[i] + nums[j] == target) { result.push_back(i); result.push_back(j); return result; } } } }
Another possible solution
*Use hashtable for efficiency
相关文章推荐
- leetCode: two Sum
- [Leetcode] Two Sum
- LeetCode 001 Two Sum
- LeetCode 1 - Two Sum
- [leetcode] two sum
- [LeetCode题解001]Two Sum
- LeetCode-1-Two Sum-E
- leetcode 1 Two Sum
- LeetCode-1.Two Sum
- LeetCode-1.Two Sum
- 【LeetCode-数组篇】 1 Two Sum
- LeetCode 1. Two Sum
- LeetCode-1- Two Sum
- 【Leetcode】1. Two Sum
- leetcode Two Sum 每日一题 (。・∀・)ノ゙嗨
- Two Sum--leetcode
- LeetCode之1—-Two Sum
- LeetCode题解 —— 1. Two Sum
- Leetcode 1: two Sum
- leetcode第一题(medium)——Two Sum