Skip to content

Commit

Permalink
이슈 #450에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 26, 2024
1 parent 0840283 commit 6083b40
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LeetCode/Product_of_Array_Except_Self.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
int n = nums.size();
vector<int> 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;
}
};

0 comments on commit 6083b40

Please sign in to comment.