From f13a508a4f5c74f0a2cd25059cb63b5ddfc3a5e6 Mon Sep 17 00:00:00 2001 From: RegiSimkus <91128330+RegiSimkus@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:56:02 +0000 Subject: [PATCH] `LC/Easy/1. Two Sum` solution submission --- .../Easy/1. Two Sum/Solution-2.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LeetCode Solutions/Easy/1. Two Sum/Solution-2.cpp diff --git a/LeetCode Solutions/Easy/1. Two Sum/Solution-2.cpp b/LeetCode Solutions/Easy/1. Two Sum/Solution-2.cpp new file mode 100644 index 00000000..0359ed42 --- /dev/null +++ b/LeetCode Solutions/Easy/1. Two Sum/Solution-2.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + vector twoSum(vector& nums, int target) { + const int size = nums.size(); + vector ret = {0, 0}; + for (unsigned short i = 0; i < size; i++) + { + for (unsigned short x = 0; x < size; x++) + { + if (i == x) continue; + int& a = nums.at(i); + int& b = nums.at(x); + if (a + b == target) + { + ret[0] = i; ret[1] = x; + return ret; + } + } + } + return ret; + } +};