Skip to content

Commit 4cbdcc0

Browse files
author
Linsen Wu
committed
comments added
1 parent f5ccd15 commit 4cbdcc0

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

C++/001_Two_Sum.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,10 @@ class Solution {
2828
};
2929

3030
/*
31-
class Solution {
32-
public:
33-
vector<int> twoSum(vector<int> &numbers, int target) {
34-
vector<int> indexResults;
35-
for(vector<int>::iterator iterator1 = numbers.begin(); iterator1 != numbers.end(); iterator1++)
36-
{
37-
for(vector<int>::iterator iterator2 = iterator1+1; iterator2 != numbers.end(); iterator2++)
38-
{
39-
if((*iterator1 + *iterator2) == target)
40-
{
41-
int index1 = iterator1 - numbers.begin() + 1;
42-
int index2 = iterator2 - numbers.begin() + 1;
43-
indexResults.push_back(index1);
44-
indexResults.push_back(index2);
45-
}
46-
}
47-
}
48-
return indexResults;
49-
}
50-
};*/
31+
Save the numbers into an unordered map when searching
32+
Time: O(n)
33+
Space: O(n)
34+
*/
5135

5236
int _tmain(int argc, _TCHAR* argv[])
5337
{

0 commit comments

Comments
 (0)