From 6083b40bd65c140c46d97cfa0d72b95be0d464f0 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 26 Dec 2024 17:37:58 +0000 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=8A=88=20#450=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=86=94=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LeetCode/Product_of_Array_Except_Self.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LeetCode/Product_of_Array_Except_Self.cpp diff --git a/LeetCode/Product_of_Array_Except_Self.cpp b/LeetCode/Product_of_Array_Except_Self.cpp new file mode 100644 index 0000000..f2a35d8 --- /dev/null +++ b/LeetCode/Product_of_Array_Except_Self.cpp @@ -0,0 +1,21 @@ +class Solution { +public: + vector productExceptSelf(vector& nums) { + int n = nums.size(); + vector result(n, 1); + + int left = 1; + for (int i = 0; i < n; i++) { + result[i] *= left; + left *= nums[i]; + } + + int right = 1; + for (int i = n - 1; i >= 0; i--) { + result[i] *= right; + right *= nums[i]; + } + + return result; + } +}; \ No newline at end of file