feat: osijvrsoi

This commit is contained in:
2026-03-06 19:17:30 -05:00
parent 2cac846a4d
commit aad6f3e91f
43 changed files with 136 additions and 0 deletions

View 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
}

View File

@@ -0,0 +1,16 @@
package product_of_array_except_self_test
import (
"testing"
"git.maximhutz.com/practice/pkg/product_of_array_except_self"
"github.com/stretchr/testify/assert"
)
func Test1(t *testing.T) {
assert.Equal(t, []int{24, 12, 8, 6}, product_of_array_except_self.ProductExceptSelf([]int{1, 2, 3, 4}))
}
func Test2(t *testing.T) {
assert.Equal(t, []int{0, 0, 9, 0, 0}, product_of_array_except_self.ProductExceptSelf([]int{-1, 1, 0, -3, 3}))
}