plain solution in python

  • 0
    class Solution(object):
        def depthSum(self, nestedList):
            :type nestedList: List[NestedInteger]
            :rtype: int
            def findSum(nestedList, level):
                sum = 0
                for nestedInteger in nestedList:
                    if nestedInteger.isInteger():
                        sum += nestedInteger.getInteger() * level
                        sum += findSum(nestedInteger.getList(), 1 + level)
                return sum
            return findSum(nestedList, 1)

Log in to reply

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