← 返回 meta 的题目列表Weighted Sum of Nested Integer Array by Depth_inverse
类型:online_judge
meta
Problem: Weighted Nested Array Sum
Given a nested integer array nestedList, calculate its weighted sum. The weight of each integer is determined by its depth in the nesting. Outer integers have a greater weight, while inner integers have a smaller weight. Nesting starts at depth 1.
Example 1:
Input: [[1,1],2,[1,1]]
Output: 10
Explanation: 1 has a weight of 2(nested within another nestedList), each appears twice, and the total sum is 1*2+1*2+2*1+1*2+1*2=10.
Example 2:
Input: [1,[4,[6]]]
Output: 27
Explanation: 1 has a weight of 3, 4 has a weight of 2, 6 has a weight of 1, and the total sum is 1*3+4*2+6*1=27.
Constraints: 1 <= total number of integers <= 1000
Implement this feature to return the weighted sum for a given nested list.
Example
Input
[[1,1],2,[1,1]]