首页 > 代码库 > leetcode238

leetcode238

public class Solution {
    public int[] ProductExceptSelf(int[] nums) {
        int[] result = new int[nums.Length];
            for (int i = 0, tmp = 1; i < nums.Length; i++)
            {
                result[i] = tmp;
                tmp *= nums[i];
            }
            for (int i = nums.Length - 1, tmp = 1; i >= 0; i--)
            {
                result[i] *= tmp;
                tmp *= nums[i];
            }
            return result;
    }
}

https://leetcode.com/problems/product-of-array-except-self/#/description

leetcode238