굴러가는 분석가의 일상

[LeetCode] Product of Array Except Self 본문

Algorithm/Leetcode

[LeetCode] Product of Array Except Self

G3LU 2023. 12. 14. 16:53

문제: 

 

풀이 : 

 

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

'Algorithm > Leetcode' 카테고리의 다른 글

[LeetCode] Valid Anagram  (0) 2024.02.16
[LeetCode] SQL 50문제 (진행중)  (0) 2023.10.24
[LeetCode] Two Sum  (0) 2023.10.20
[LeetCode] Valid Sudoku  (0) 2023.10.12
[LeetCode] Contains Duplicate  (0) 2023.10.10