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 437976f commit 9afbc0bCopy full SHA for 9afbc0b
product-of-array-except-self/yhkee0404.rs
@@ -0,0 +1,16 @@
1
+impl Solution {
2
+ pub fn product_except_self(nums: Vec<i32>) -> Vec<i32> {
3
+ let mut ans = vec![1; nums.len()];
4
+ let mut a = 1;
5
+ for i in (0..nums.len()).rev() {
6
+ ans[i] = a * nums[i];
7
+ a = ans[i];
8
+ }
9
+ a = 1;
10
+ for i in 0..nums.len() {
11
+ ans[i] = a * (if i == nums.len() - 1 {1} else {ans[i + 1]});
12
+ a *= nums[i];
13
14
+ return ans
15
16
+}
0 commit comments