diff --git a/C++/two-sum.cpp b/C++/two-sum.cpp index 7720f6d83..841d2e1a5 100644 --- a/C++/two-sum.cpp +++ b/C++/two-sum.cpp @@ -4,15 +4,13 @@ class Solution { public: vector twoSum(vector& nums, int target) { - vector res; unordered_map 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 {}; } };