classSolution:defdepthSumInverse(self,nestedList:'List[NestedInteger]') ->'int': total, level =0,0whilelen(nestedList): nextLevel = []for x in nestedList:if x.isInteger(): level += x.getInteger()else:for y in x.getList(): nextLevel.append(y) total += level nestedList = nextLevelreturn total