파이썬 알고리즘 인터뷰 문제 11번(리트코드 238번) Product of Array Except Self
https://leetcode.com/problems/product-of-array-except-self/
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
result = []
multiple = 1
for left in range(len(nums)):
result.append(multiple)
multiple *= nums[left]
multiple = 1
for right in range(len(nums) - 1, 0, -1):
multiple *= nums[right]
result[right - 1] *= multiple
return result
코드를 짜기 전에 인간인 내가 어떤 식으로 이 문제를 푸는 지 생각해보는 것이 많은 도움이 된다.