C++_Recursive_Accepted!


  • 0

    Update:

    class Solution {
    public:
    int depthSum(vector<NestedInteger>& nestedList) {
        return decode(nestedList,1);
    }
    
    int decode(vector<NestedInteger>& nList, int k){
        int n = nList.size();
        int res = 0;
        for(int i = 0; i < n; ++i){
            if(nList[i].isInteger()){
                res += nList[i].getInteger()*k;
            }else{
                res += decode(nList[i].getList(), k+1);
            }
        }
        return res;
    }
    };

Log in to reply
 

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