Created
March 17, 2020 08:25
-
-
Save alldroll/cafe5badeebb9de9d045f214d0f40614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/product-of-array-except-self | |
| func productExceptSelf(nums []int) []int { | |
| numsLen := len(nums) | |
| product := make([]int, numsLen) | |
| product[0] = 1 | |
| for i := 1; i < numsLen; i++ { | |
| product[i] = product[i - 1] * nums[i - 1] | |
| } | |
| r := 1 | |
| for i := numsLen - 1; i >= 0; i-- { | |
| product[i] = product[i] * r | |
| r *= nums[i] | |
| } | |
| return product | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment