From 98591a60238f14c586e54eeb6ef988701857dc8b Mon Sep 17 00:00:00 2001 From: Betty Date: Wed, 11 Sep 2024 20:27:37 +0800 Subject: [PATCH 1/2] o(n^2) solution --- two_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two_sum.cpp b/two_sum.cpp index ac6a162..322e79a 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 && nums[i]+nums[j]==target) { // found pair return {i, j}; } From cad04bfa9312c116500b89f16f53b904143d435b Mon Sep 17 00:00:00 2001 From: Betty Date: Wed, 11 Sep 2024 20:49:25 +0800 Subject: [PATCH 2/2] PR again --- two_sum.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/two_sum.cpp b/two_sum.cpp index 322e79a..213098c 100644 --- a/two_sum.cpp +++ b/two_sum.cpp @@ -9,6 +9,8 @@ vector twoSum(vector& nums, int target) { for (int j = 0; j < n; j++) { if (i != j && nums[i]+nums[j]==target) { // found pair + + return {i, j}; } }