No depth variable

  • 0

    The .real part of calc's result is the weighted sum, the .imag part is the unweighted sum.

    def depthSum(self, nestedList):
        def calc(nestedList):
            s = sum(x.getInteger() * 1j if x.isInteger() else calc(x.getList())
                    for x in nestedList)
            return s + s.imag
        return int(calc(nestedList).real)

  • 4

    Though less lines of code, the readability is bad...

Log in to reply

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