We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cf13a2f commit ebe1913Copy full SHA for ebe1913
1 file changed
swordoffer/MultiplySolution.java
@@ -0,0 +1,31 @@
1
+/**
2
+ *
3
+ */
4
+import java.util.ArrayList;
5
+public class MultiplySolution {
6
+
7
8
+ public int[] multiply(int[] A) {
9
10
+ int tmp = 1;
11
+ int[] L = new int[A.length];
12
+ for(int i = 0; i < A.length; i++) {
13
+ L[i] = tmp * A[i];
14
+ tmp = L[i];
15
+ }
16
+ tmp = 1;
17
+ int[] R = new int[A.length];
18
+ for (int i = A.length - 1; i >= 0; i --) {
19
+ R[i] = tmp * A[i];
20
+ tmp = R[i];
21
22
23
+ int[] B = new int[A.length];
24
+ B[0] = R[1];
25
+ B[A.length-1] = L[A.length-2];
26
+ for (int i = 1; i < A.length - 1; i++) {
27
+ B[i] = L[i-1] * R[i+1];
28
29
+ return B;
30
31
+}
0 commit comments