2 lines fastest Python Solution.


  • 0
    S
    class Solution(object):
        def depthSum(self, nestedList, depth=1, curr=0):
            for num in nestedList:
                curr += num.getInteger() * depth if num.isInteger() else self.depthSum(num.getList(), depth+1) 
            return curr
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.