-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path30-day-leetcoding-challenge-530-week-3-3300.cpp
48 lines (48 loc) · 1.22 KB
/
30-day-leetcoding-challenge-530-week-3-3300.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
int count=0;
for(int i=0;i<nums.size();i++){
if(nums[i]==0){
count++;
}
}
if(count==0){
long long int pro=1;
for(int i=0;i<nums.size();i++){
pro=pro*nums[i];
}
vector<int>B;
for(int j=0;j<nums.size();j++){
B.push_back(pro/nums[j]);
}
return B;
}
else if(count==1){
long long int pro=1;
vector<int>B;
for(int i=0;i<nums.size();i++){
if(nums[i]!=0){
pro=pro*nums[i];
}
}
for(int i=0;i<nums.size();i++){
if(nums[i]!=0){
B.push_back(0);
}
else if(nums[i]==0){
B.push_back(pro);
}
}
return B;
}
else if(count>=2){
vector<int>B;
for(int j=0;j<nums.size();j++){
B.push_back(0);
}
return B;
}
return nums;
}
};