Skip to content

Commit 1da1f91

Browse files
author
Linsen Wu
committed
add the problem in the code, uodate the code to match the latest change in LeetCode
1 parent 4cbdcc0 commit 1da1f91

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

C++/001_Two_Sum.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
//Author: Linsen Wu
1+
/*
2+
*Given an array of integers, return indices of the two numbers such that they add up to a specific target.
3+
*You may assume that each input would have exactly one solution.
4+
5+
*Example:
6+
*Given nums = [2, 7, 11, 15], target = 9,
7+
*Because nums[0] + nums[1] = 2 + 7 = 9,
8+
*return [0, 1].
9+
10+
*UPDATE (2016/2/13):
11+
*The return format had been changed to zero-based indices. Please read the above updated description carefully
12+
13+
*Tag: Array, Hash Table
14+
15+
*Author: Linsen Wu
16+
*/
217

318
#include "stdafx.h"
419
#include "iostream"
@@ -17,10 +32,10 @@ class Solution {
1732
it = index_map.find(target-numbers[i]);
1833
if (it != index_map.end()) {
1934
indexResults.push_back(it->second);
20-
indexResults.push_back(i+1);
35+
indexResults.push_back(i);
2136
return indexResults;
2237
} else {
23-
index_map[numbers[i]] = i+1;
38+
index_map[numbers[i]] = i;
2439
}
2540
}
2641
return indexResults;

0 commit comments

Comments
 (0)