Python solution


  • 0
    A
    def depthSum(self, nestedList,level=1):
        """
        :type nestedList: List[NestedInteger]
        :rtype: int
        """
        sum = 0
        for element in nestedList:
            if element.isInteger():
                sum += element.getInteger()*level
            else:
                sum += self.depthSum(element.getList(),level + 1)
        return sum

Log in to reply
 

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