impl: q238, q380

This commit is contained in:
kanna5 2025-12-08 14:52:29 +09:00
parent cc7fb41dfc
commit 411a71bd16
4 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,24 @@
package q238
func productExceptSelf(nums []int) []int {
ret := make([]int, len(nums))
// from left
t := 1
for i := range len(nums) - 1 {
t *= nums[i]
ret[i+1] = t
}
ret[0] = 1
// from right
t = 1
for i := len(nums) - 1; i > 0; i-- {
t *= nums[i]
ret[i-1] *= t
}
return ret
}
var _ = productExceptSelf