C# solution to Product of Array Except Self


  • 0
    R

    O(N) Time (Sum - O(N), for loop - O(N) - > O(2N) = O(N))
    O(1) Space

            public int[] ProductOfArrayExceptSelf(int[] nums)
            {
                int current;
                int sum = nums.Sum();
                for (int i = 0; i < nums.Length; i++)
                {
                    current = nums[i];
                    nums[i] = sum - current;
                }
                return nums;
            }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.