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 bf97331 commit 0999d34Copy full SHA for 0999d34
product-of-array-except-self/hyunjung-choi.kt
@@ -0,0 +1,16 @@
1
+class Solution {
2
+ fun productExceptSelf(nums: IntArray): IntArray =
3
+ IntArray(nums.size) { 1 }.apply {
4
+ var leftProduct = 1
5
+ for (i in 1 until nums.size) {
6
+ leftProduct *= nums[i - 1]
7
+ this[i] = leftProduct
8
+ }
9
+
10
+ var rightProduct = 1
11
+ for (i in nums.size - 2 downTo 0) {
12
+ rightProduct *= nums[i + 1]
13
+ this[i] *= rightProduct
14
15
16
+}
0 commit comments