728x90
https://leetcode.com/problems/product-of-array-except-self
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
result = [1] * len(nums)
prifix_value = 1
for i in range(0, len(nums)):
result[i] *= prifix_value
prifix_value *= nums[i]
suffix_value = 1
for i in range(len(nums)-1, -1, -1):
result[i] *= suffix_value
suffix_value *= nums[i]
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 3079. Find the Sum of Encrypted Integers (0) | 2024.03.16 |
---|---|
[Leetcode] 525. Contiguous Array (0) | 2024.03.16 |
[Leetcode] 930. Binary Subarrays With Sum (1) | 2024.03.14 |
[Leetcode] 2485. Find the Pivot Integer (0) | 2024.03.13 |
[Leetcode] 791. Custom Sort String (0) | 2024.03.11 |