[LeetCode][Python3] 238. Product of Array Except Self
2019. 1. 12. 00:32 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/product-of-array-except-self/
My Solution :
class Solution:
def productExceptSelf(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
n = len(nums)
ret = [1 for _ in range(n)]
for i in range(1, n):
ret[i] = nums[i-1] * ret[i-1]
a = nums[-1]
for j in range(n-2, -1, -1):
ret[j] *= a
a *= nums[j]
return ret
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 102. Binary Tree Level Order Traversal (0) | 2019.01.22 |
---|---|
[LeetCode][Python3] 230. Kth Smallest Element in a BST (0) | 2019.01.15 |
[LeetCode][Python3] 454. 4Sum II (1) | 2019.01.13 |
[LeetCode][Python3] 78. Subsets (0) | 2019.01.13 |
[LeetCode][Python3] 347. Top K Frequent Elements (0) | 2019.01.05 |
[LeetCode][Python3] 94. Binary Tree Inorder Traversal (1) | 2019.01.03 |
[LeetCode][Python3] 62. Unique Paths (6) | 2018.11.15 |
[LeetCode][Python3] 55. Jump Game (0) | 2018.11.15 |
최근에 달린 댓글 최근에 달린 댓글