..

###### 1 Two Sum

Two Sum

class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> v(2,0);
for (int i = 0; i < nums.size(); i++){
for (int j = i+1; j < nums.size(); j++){
if (nums[i] + nums[j] == target){
v[0] = i;
v[1] = j;
return v;
}
}
}
}
};

public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
map.put(nums[i], i);
}
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement) && map.get(complement) != i) {
return new int[] { i, map.get(complement) };
}
}
throw new IllegalArgumentException("No two sum solution");
}

public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[] { map.get(complement), i };
}
map.put(nums[i], i);
}
throw new IllegalArgumentException("No two sum solution");
}

#### [LeetCode]1 Two Sum(C++,Python实现)

2014-05-16 21:17:33

#### leetcode 刷题题解（c++） 1.Two Sum （hash表，排序+二分查找）

2016-07-24 20:59:08

#### leetcode 1. Two Sum -----java

2016-06-20 19:52:04

#### 【LeetCode】LeetCode——第1题：Two Sum

2016-01-04 17:01:58

#### 1. Two Sum（重要！）

2016-07-09 16:21:27

#### 1. Two Sum [easy] (Python)

2016-07-26 20:19:37

#### leetcode【1+167 Two Sum 系列】【python】

2016-09-01 19:31:36

#### LeetCode题解--1. Two Sum(和为S的两个数字)

2016-01-27 22:32:25

#### leetcode－1. Two Sum－简单的算法题，面试见到了吗？

2016-09-17 12:11:51

#### [LeetCode][1]Two Sum解析 -Java实现

2016-06-01 16:23:30

1 Two Sum