Skip to content

Commit cef1274

Browse files
committed
product of array except self
1 parent d859932 commit cef1274

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
func productExceptSelf(_ nums: [Int]) -> [Int] {
3+
var answer = [Int]()
4+
var product:Int = 1
5+
for i in (0..<nums.count) {
6+
if i > 0 {
7+
product *= nums[i-1]
8+
}
9+
answer.append(product)
10+
}
11+
12+
product = 1
13+
for i in (1..<nums.count) {
14+
product *= nums[nums.count-i]
15+
answer[nums.count-1-i] *= product
16+
}
17+
18+
return answer
19+
20+
//시간 복잡도 O(n)
21+
//공간 복잡도 O(n)
22+
}
23+
}
24+

0 commit comments

Comments
 (0)