C++ now don't have hash_map in STL?


  • 0
    R
    class Solution {
    public:
        RandomListNode *copyRandomList(RandomListNode *head) {
            hash_map <RandomListNode*, RandomListNode*> map;
            RandomListNode * tmp=head;
            while(tmp!=NULL){
                map[tmp]=new RandomListNode(tmp->label);
                tmp=tmp->next;
            }
            tmp=head;
            while(tmp!=NULL){
                map[tmp]->next=map[tmp->next];
                map[tmp]->random=map[tmp->random];
                tmp=tmp->next;
            }
            return map[head];
        }
    };
    

    I use hash_map to store the pair here, but the compiler always said " hash_map was not declared in this scope"?


  • 0
    J

    renquingmei,

    I think the container you are looking for is: std::unordered_map.

    The prefix "hash_" was not accepted. The committee chose to use the prefix "unordered_" for hash tables.

    Jon Kalb


Log in to reply
 

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