fix: december
This commit is contained in:
25
pkg/product_of_array_except_self/main.go
Normal file
25
pkg/product_of_array_except_self/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package product_of_array_except_self
|
||||
|
||||
func ProductExceptSelf(nums []int) []int {
|
||||
result := []int{}
|
||||
|
||||
for range nums {
|
||||
result = append(result, 1)
|
||||
}
|
||||
|
||||
lower_sum := 1
|
||||
|
||||
for i := range len(nums) {
|
||||
result[i] *= lower_sum
|
||||
lower_sum *= nums[i]
|
||||
}
|
||||
|
||||
upper_sum := 1
|
||||
|
||||
for i := range len(nums) {
|
||||
result[len(nums)-1-i] *= upper_sum
|
||||
upper_sum *= nums[len(nums)-1-i]
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user