I really have no idea what's wrong


  • 2
    L
    UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) {
        unordered_map<int, int> aux;
        //vector<UndirectedGraphNode*> q;
        if(!node) return NULL;
        UndirectedGraphNode* res = new UndirectedGraphNode(node->label);
        aux[res->label] = 1;
        helper(node, res, &aux);
        return res;
    }
    void helper(UndirectedGraphNode* old, 
                UndirectedGraphNode* cp, unordered_map<int, int>* aux) {
        for (auto nb: old->neighbors) {
           UndirectedGraphNode * cur = new UndirectedGraphNode(nb->label);
            cp->neighbors.push_back(cur);
            if(aux->find(nb->label) == aux->end()) {
               (*aux)[nb->label] = 1;
               helper (nb, cur, aux);
            }
        }
    }
    

    test case {0,0,0} , my output is {0,0,0#0#0}

    could anybody help me, Thank you very much


Log in to reply
 

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