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 5fe4ef9 commit 7aa7393Copy full SHA for 7aa7393
product-of-array-except-self/kimjunyoung90.java
@@ -0,0 +1,20 @@
1
+public class kimjunyoung90 {
2
+ public int[] productExceptSelf(int[] nums) {
3
+ int[] answers = new int[nums.length];
4
+
5
+ //왼쪽 값 계산
6
+ answers[0] = 1;
7
+ for (int i = 1; i < nums.length; i++) {
8
+ answers[i] = answers[i - 1] * nums[i - 1];
9
+ }
10
11
+ //오른쪽 값 계산
12
+ int right = 1;
13
+ for (int i = nums.length - 1; i >= 0; i--) {
14
+ answers[i] *= right;
15
+ //다음 값 right 계산
16
+ right *= nums[i];
17
18
+ return answers;
19
20
+}
0 commit comments