标签:
An intuitive DFS one.
class Solution(object): def go(self, nList, dep): ret = 0 for i in range(len(nList)): if(nList[i].isInteger()): ret += dep * (nList[i].getInteger()) else: ret += self.go(nList[i].getList(), dep + 1) return ret def depthSum(self, nestedList): return self.go(nestedList, 1)
LeetCode "Nested List Weight Sum"
标签:
原文地址:http://www.cnblogs.com/tonix/p/5339629.html