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 1b27cf3 commit 6cf0af6Copy full SHA for 6cf0af6
product-of-array-except-self/WhiteHyun.swift
@@ -0,0 +1,27 @@
1
+//
2
+// 238. Product of Array Except Self
3
+// https://leetcode.com/problems/product-of-array-except-self/description/
4
+// Dale-Study
5
6
+// Created by WhiteHyun on 2024/06/01.
7
8
+
9
+final class Solution {
10
+ func productExceptSelf(_ nums: [Int]) -> [Int] {
11
+ var answer: [Int] = .init(repeating: 1, count: nums.count)
12
13
+ var left_product = 1
14
+ for i in nums.indices {
15
+ answer[i] = left_product
16
+ left_product *= nums[i]
17
+ }
18
19
+ var right_product = 1
20
+ for i in nums.indices.reversed() {
21
+ answer[i] *= right_product
22
+ right_product *= nums[i]
23
24
25
+ return answer
26
27
+}
0 commit comments