Advertisement
lazar955

Untitled

Oct 22nd, 2023
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.30 KB | None | 0 0
  1. func productExceptSelf(nums []int) []int {
  2.     res:=make([]int,len(nums))
  3.  
  4.     prefix:=1
  5.     for i:= range nums {
  6.         res[i] = prefix
  7.         prefix *=nums[i]
  8.     }
  9.     postfix:=1
  10.     for i:=len(nums) -1;i>=0;i-- {
  11.         res[i] *=postfix
  12.         postfix *=nums[i]
  13.     }
  14.     return res
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement