← 返回 amazon 的题目列表Calculate Nested List Weight Sum
类型:online_judge
Given a nested list of integers, implement a function to calculate the weighted sum of the list. The weight of each element in the list is defined by its depth. The list may contain integers and other lists. You need to implement both depth-first search and breadth-first search methods. Provide time complexity analysis and include several test cases.
Example
Input: [[1,1],2,[1,1]] Output: 10 Explanation: four 1 at depth 1 and one 2 at depth 2, weighted sum: 41 + 21 = 10
Input Constraints
The number of elements in the list does not exceed 1000.
Each element value ranges from -100 to 100.
Example
Input
[[1,1],2,[1,1]]