0ms solution


  • 0
    B
     int cal(struct NestedInteger** nestedList , int size , int weight){
         int tmp = 0;
         for (int i = 0;i < size ;i++){
             struct NestedInteger** p = nestedList + i;
             if (NestedIntegerIsInteger(*p)){
                 tmp += NestedIntegerGetInteger(*p) * weight;
             }else{
                 tmp += cal((NestedIntegerGetList(*p)) , NestedIntegerGetListSize(*p) , weight + 1);
             }
         }
         return tmp;
     }
     
     
     
    int depthSum(struct NestedInteger** nestedList, int nestedListSize) {
        return cal(nestedList , nestedListSize , 1);
    }
    

Log in to reply
 

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