From 9892bb4a25a9c91be0edd402c835a4f13c7babae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E4=BA=A6=E8=8C=97?= <15946078+Zyming2006@user.noreply.gitee.com> Date: Tue, 16 Sep 2025 12:04:17 +0000 Subject: [PATCH] =?UTF-8?q?add=20exercise/LC0001=5F=E6=9B=BE=E4=BA=A6?= =?UTF-8?q?=E8=8C=97.cpp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 曾亦茗 <15946078+Zyming2006@user.noreply.gitee.com> --- .../LC0001_\346\233\276\344\272\246\350\214\227.cpp" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "exercise/LC0001_\346\233\276\344\272\246\350\214\227.cpp" diff --git "a/exercise/LC0001_\346\233\276\344\272\246\350\214\227.cpp" "b/exercise/LC0001_\346\233\276\344\272\246\350\214\227.cpp" new file mode 100644 index 0000000..0a2cd10 --- /dev/null +++ "b/exercise/LC0001_\346\233\276\344\272\246\350\214\227.cpp" @@ -0,0 +1,12 @@ +class Solution { +public: + vector twoSum(vector& nums, int target) { + unordered_map m; + for (int i = 0; i < nums.size(); i++) { + int x = target - nums[i]; + if (m.count(x)) return {m[x], i}; + m[nums[i]] = i; + } + return {}; + } +}; \ No newline at end of file -- Gitee