We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 666eca4 commit f29e28fCopy full SHA for f29e28f
0238-product-of-array-except-self/0238-product-of-array-except-self.rs
@@ -0,0 +1,40 @@
1
+impl Solution {
2
+ pub fn product_except_self(nums: Vec<i32>) -> Vec<i32>
3
+ {
4
+ let n = nums.len();
5
+ let mut p =1;
6
+ let mut zero = 0;
7
+ let mut zeroi = 0usize;
8
+ let mut ans = vec![0;n];
9
+
10
+ for i in 0..n
11
12
+ if(nums[i]==0)
13
14
+ zero+=1;
15
+ zeroi = i;
16
+ }else
17
18
+ //product of all element
19
+ p=p*nums[i];
20
+ }
21
22
+ if(zero>1)
23
24
+ //multiple zero, so all elements will become zero
25
+ return ans;
26
27
+ else if(zero==1)
28
29
+ //if one zero position only that position have multiplied p
30
+ ans[zeroi]=p;
31
32
33
34
35
+ //total multiplied value divided by current position
36
+ ans[i]=p/nums[i];
37
38
39
40
+}
0 commit comments