Got Output Limit Exceeded


  • 0
    J
    UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) {
      if(node == NULL) return NULL;
      unordered_map<UndirectedGraphNode *, UndirectedGraphNode *> map;
      queue<UndirectedGraphNode *> q;
      q.push(node);
      UndirectedGraphNode *nodeCopy = new UndirectedGraphNode(node->label);
      map[node] = nodeCopy;
      while(!q.empty()){
        UndirectedGraphNode *cur = q.front();
        q.pop();
        for(int i=0;i<cur->neighbors.size();i++){
          UndirectedGraphNode *neighbor = cur->neighbors[i];
          if(map.find(neighbor)==map.end()){
            UndirectedGraphNode *newNode = new UndirectedGraphNode(cur->label);
            map[cur]->neighbors.push_back(newNode);
            map[neighbor] = newNode;
            q.push(neighbor);
          } else {
            map[cur]->neighbors.push_back(map[neighbor]);
          }   
        }   
      }
      return nodeCopy;
    }
    

    I implmented clone graph according to this description http://leetcode.com/2012/05/clone-graph-part-i.html. But I got a output limit exceed.


Log in to reply
 

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