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 ef0b325 commit 06a3f3dCopy full SHA for 06a3f3d
product-of-array-except-self/delight010.swift
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ func productExceptSelf(_ nums: [Int]) -> [Int] {
3
+ var answer: [Int] = Array(repeating: 1, count: nums.endIndex)
4
+ for i in 1..<nums.endIndex {
5
+ answer[i] = answer[i - 1] * nums[i - 1]
6
+ }
7
+
8
+ var suffix = 1
9
+ for i in (0..<nums.endIndex).reversed() {
10
+ answer[i] *= suffix
11
+ suffix *= nums[i]
12
13
14
+ return answer
15
16
+}
17
0 commit comments