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 af4f23c commit 906ec0eCopy full SHA for 906ec0e
product-of-array-except-self/mumunuu.java
@@ -0,0 +1,31 @@
1
+class Solution {
2
+ public int[] productExceptSelf(int[] nums) {
3
+
4
+ // 원래는 그냥 다 곱해서 자기 빼고 나누면 되는데 나눗셈 하지 말라고 함
5
6
+ // 왼쪽 곱 구한다음에 오른쪽 곱으로 리턴하면 됨
7
+ int[] answer = new int[nums.length];
8
9
+ int left = 1;
10
+ answer[0] = left;
11
12
+ for (int i = 1; i < nums.length; i++) {
13
+ answer[i] = answer[i - 1] * nums[i - 1];
14
+ }
15
16
+ // 1 1 2 6
17
18
+ // 오른쪽 누적 곱
19
20
+ int right = 1;
21
22
+ for (int i = nums.length - 1; i >= 0; i--) {
23
+ answer[i] = answer[i] * right;
24
+ right *= nums[i];
25
26
27
28
+ return answer;
29
30
31
+}
0 commit comments