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 bbf7872 commit caabec4Copy full SHA for caabec4
product-of-array-except-self/dohee789.java
@@ -0,0 +1,25 @@
1
+/*
2
+https://leetcode.com/problems/product-of-array-except-self/
3
+ */
4
+class Solution {
5
+ public int[] productExceptSelf(int[] nums) {
6
+ int n = nums.length;
7
+ int[] result = new int[n];
8
+
9
+ result[0] = 1;
10
+ for (int i = 1; i < n; i++) {
11
+ result[i] = result[i - 1] * nums[i - 1];
12
+ }
13
14
+ int right = 1;
15
+ for (int i = n - 1; i >= 0; i--) {
16
+ result[i] *= right;
17
+ right *= nums[i];
18
19
20
+ return result;
21
22
+}
23
24
25
0 commit comments