JavaScript Solution


  • 0
    K
    
    var depthSum = function(nestedList) {
        var self = this;
        
        function checkChildren(list, currentDepth) {
            var sum = 0;
            var idx = 0;
            for(idx = 0; idx < list.length; idx++){
                if(list[idx].isInteger()){
                    sum += currentDepth*list[idx].getInteger();
                } else {
                    sum += checkChildren(list[idx].getList(), currentDepth + 1);
                }
            }
            
            return sum;
        }
    
    
    return checkChildren(nestedList, 1);
    

    };


Log in to reply
 

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