1ms java solution


  • 0
    N
    int depth = 1, sum = 0;
    public int depthSum(List<NestedInteger> nestedList) {
        for(NestedInteger n : nestedList)
        {
            if(n.isInteger())
                sum += n.getInteger() * depth;
            else
            {
                depth++;
                sum = depthSum(n.getList());
            }
        }
        depth--;
        return sum;
    }

Log in to reply
 

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