# Tip: You can use the type(element) function to check whether an item
# is a list or an integer.
def productSum(array):
# Write your code here.
return productHelper(array, 1)
# m: multiply value
def productHelper(array, m):
sum = 0
for x in array:
if type(x) == list:
sum += (m+1) * productHelper(x, m+1)
else:
sum += x
return sum
'Algorithms and Data Structures > Coding Practices' 카테고리의 다른 글
Kattis Quadrant Selection (0) | 2022.07.15 |
---|---|
LeetCode LinkedList Cycle II (0) | 2022.07.15 |
AlgoExpert Fibonacci (0) | 2022.07.15 |
Kattis 3D printer (0) | 2022.07.14 |
LeetCode 15. 3Sums (0) | 2022.07.14 |