Skip to content

Commit

Permalink
Update two-sum.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Apr 15, 2016
1 parent d26e24d commit fc92d7f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions C++/two-sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> res;
unordered_map<int, int> lookup;
for (int i = 0; i < nums.size(); ++i) {
if (lookup.count(target - nums[i])) {
res = {lookup[target - nums[i]], i};
break;
return {lookup[target - nums[i]], i};
}
lookup[nums[i]] = i;
}
return res;
return {};
}
};

0 comments on commit fc92d7f

Please sign in to comment.