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 c2aa005 commit ebd571eCopy full SHA for ebd571e
product-of-array-except-self/PDKhan.cpp
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public:
3
+ vector<int> productExceptSelf(vector<int>& nums) {
4
+ int zero = 0;
5
+ int product = 1;
6
+ vector<int> result;
7
+
8
+ for(int i = 0; i < nums.size(); i++){
9
+ if(nums[i] == 0)
10
+ zero++;
11
+ else
12
+ product *= nums[i];
13
+ }
14
15
16
+ if(zero > 1)
17
+ result.push_back(0);
18
+ else if(zero == 1){
19
20
+ result.push_back(product);
21
22
23
+ }else
24
+ result.push_back(product / nums[i]);
25
26
27
+ return result;
28
29
+ };
0 commit comments