diff --git a/two_sum.cpp b/two_sum.cpp index ac6a162..2d0c9c2 100644 --- a/two_sum.cpp +++ b/two_sum.cpp @@ -7,7 +7,7 @@ vector twoSum(vector& nums, int target) { int n = nums.size(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { - if (/* TODO */) { + if (i != j && num[i]+num[j] == target) { // found pair return {i, j}; } @@ -20,4 +20,5 @@ int main() { vector v = {2,4,7,9,11,19}; vector ans = twoSum(v, 15); cout<< "The indices of the two numbers that add up to target: " << ans[0] << ", " << ans[1]; + } \ No newline at end of file