[LeetCode] Product of Array Except Self (Python)

Evan Lee·2023년 9월 19일

여기의 내용은 NeetCode 유튜버 동영상을 기반으로 작성되었으므로, 문제 발생 시 즉각적으로 삭제하도록 하겠습니다.

문제

풀이


class Solution:
    def productExceptSelf(self, nums: List[int]) -> List[int]:
        
        solution = [1] * (range(len(nums)) 
             
        
        for i in range(len(nums)): 
        	solution[i] = solution[i-1] * nums[i-1] 
        
        postfix = 1
        for i in range(len(nums)-1, -1,-1)): 
        	solution[i] *= postfix
            postfix *= nums[i]

		return solution 

0개의 댓글