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 942ff43 commit 7fff63dCopy full SHA for 7fff63d
product-of-array-except-self/doitduri.swift
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ func productExceptSelf(_ nums: [Int]) -> [Int] {
3
+ let length = nums.count
4
+ var result = Array(repeating: 1, count: length)
5
+ var leftProduct = 1
6
+ for i in 0..<length {
7
+ result[i] = leftProduct
8
+ leftProduct *= nums[i]
9
+ }
10
+
11
+ var rightProduct = 1
12
+ for i in (0..<length).reversed() {
13
+ result[i] *= rightProduct
14
+ rightProduct *= nums[i]
15
16
17
+ return result
18
19
+}
0 commit comments