Nested List Weight Sum
Question (LC.339)
Example
I: [[1,1],2,[1,1]]
O: 2*2 + 2 + 2*2 = 10
I: [1,[4,[6]]]
O: 1 + 4 * 2 + 6 * 3 = 1 + 8 + 18 = 27DFS Approach
1. define subproblem
dfsSum will sum up all possible sum for the current level
2. recursive calls
currentSum += sumDfs()
3. stop condition
end of the list returnCode
BFS Approach
Code
Follow Up (LC.364)
Example
DFS Approach
BFS Approach
Last updated