Python left & right scan


  • 0
    D
    class Solution(object):
        def productExceptSelf(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            if not nums:
                return []
            res = [1]
            for i in range(1, len(nums)):
                res.append(res[-1] * nums[i-1])
            total = nums[-1]
            for i in range(len(nums)-1)[::-1]:
                res[i] *= total
                total *= nums[i]
            return res
    

Log in to reply
 

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