We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a554bbd commit 5527f2bCopy full SHA for 5527f2b
product-of-array-except-self/dylan-jung.cpp
@@ -0,0 +1,20 @@
1
+class Solution {
2
+public:
3
+ vector<int> productExceptSelf(vector<int>& nums) {
4
+ vector<int> ans;
5
+ ans.resize(nums.size(), 1);
6
+ int p = 1;
7
+ int idx = nums.size()-1;
8
+ for(auto it = nums.rbegin(); it != nums.rend(); it++, idx--) {
9
+ ans[idx] *= p;
10
+ p *= *it; // 마지막 건 그냥 무시
11
+ }
12
+ p = 1;
13
+ idx = 0;
14
+ for(auto it = nums.begin(); it != nums.end(); it++, idx++) {
15
16
+ p *= *it;
17
18
+ return ans;
19
20
+};
0 commit comments