Skip to content

Commit 2182c6e

Browse files
committed
Update two-sum.cpp
1 parent 207a127 commit 2182c6e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

C++/two-sum.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
class Solution {
55
public:
66
vector<int> twoSum(vector<int>& nums, int target) {
7-
vector<int> res;
87
unordered_map<int, int> lookup;
98
for (int i = 0; i < nums.size(); ++i) {
109
if (lookup.count(target - nums[i])) {
11-
res = {lookup[target - nums[i]], i};
12-
break;
10+
return {lookup[target - nums[i]], i};
1311
}
1412
lookup[nums[i]] = i;
1513
}
16-
return res;
14+
return {};
1715
}
1816
};

0 commit comments

Comments
 (0)